Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib plots not showing in VS Code

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()
like image 211
David Zanger Avatar asked Feb 09 '21 15:02

David Zanger


1 Answers

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.

like image 195
arhr Avatar answered Sep 28 '22 09:09

arhr