Matplotlib plots not showing in VS Code
Solution 1
When you are plotting a graph in a script, make sure to use the following command to output the window displaying the graph.
plt.show()
By default, Jupyter outputs the graph, even when plt.show()
is not explicitly called.
Solution 2
In Visual Studio Code Jupyter Notebooks you may see something like this:
in order to show the plot you may click on the
</>
symbol to the left and change the the mime type to image/png (Jupyter renderer).
Now the plot appears.
Solution 3
Try the latest version of matplotlib
pip install matplotlib --upgrade
This works good for me.
David Zanger
Updated on June 09, 2022Comments
-
David Zanger almost 2 years
I am running Windows 10 and when I run a script that use matplotlib.pyplot to create a plot, no plot is created if I run in the embedded terminal (either bash or powershell) in vscode. However, the figure window is shown in my task bar but I cannot open it.
I still get a plot when I run the script in jupyter. I also get a plot window when I run the script in the 'Terminal' app. So, I figured this problem has something to do with vscode.
The code I use is really simple:
import matplotlib.pyplot as plt x = [1, 1] plt.plot(x) plt.show()
-
David Zanger over 3 yearsI'm already using plt.show() but it still does not work. It just creates the window but with no plot. I also can not open the window, it is just in the task bar.
-
Admin over 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.