Issue
I'm following a Python tutorial book I have (Python Crash Course 2nd Edition) and I'm currently doing Project 2, where they teach about visually representing data with things such as Matplotlib. Unfortunately, the code I run (which is the same as the code in the book) doesn't make a graph show up anywhere.
The book I'm following expects you to be running the code in Sublime Text, while I'm running it in VS Code, so I originally thought that maybe Sublime would show the graph automatically, but it doesn't when I tried to run the code over there.
This is my code:
import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
fig, ax = plt.subplots()
ax.plot(squares)
plt.show()
And I have installed matplotlib in the terminal, using this command:
$ python -m pip install --user matplotlib
The book I'm following says that, "The function plt.show()
opens Matplotlib's viewer and displays the plot as shown in Figure 15-1. The viewer allows you to zoom and navigate the plot, and when you click the disk icon, you can save any plot images you like." Figure 15-1 shows a graph with the various different points connected with lines. And remember, even running the code on Sublime doesn't make the Matplotlib viewer show up.
I'm on Windows 11. VS is using Python 3.10.8, while I have Python 3.12 installed on my laptop (I don't know how to update this on VS though).
Thanks for any help!
Solution
Do you mind using Jupyter to run your Matplotlib Python code.
You can install jupyter extension in extension store.
Then create a .ipynb
file and choose the python kernel. Running your python codes in the Jupyter cell may be more intuitive and convenient.
Answered By - MingJie-MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.