Issue
I´m a noobie with python, but I discover that with vscode I can´t save plots, but if I run the same code with Spyder the plot is saved to the path where the script is. Is there an option that I need to activate in VScode?
Example code:
import matplotlib.pyplot as plt
# creating plotting data
xaxis =[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
yaxis =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# plotting
plt.plot(xaxis, yaxis)
plt.xlabel("X")
plt.ylabel("Y")
# saving the file.Make sure you
# use savefig() before show().
plt.savefig("squares.png", format="png")
plt.close()
Solution
I tested with the latest version of VS Code and a previous historical version and restored all settings to default.
The code you show all generates squares.png
in my current working directory.
So please make sure that you are running this code file in the workspace, not just open this code file with VS Code, because then VS Code will not be able to find your working environment.
After testing, if you just open this code file in VS Code, the picture will be generated in your computer user folder.For me it was in C:\Users\Admin
Answered By - JialeDu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.