我在linux shell上使用python,并试图保存绘图而不是显示(显示绘图窗口会导致错误)。我看了看问题Save plot to image file instead of displaying it using Matplotlib,但没有帮助。下面是我的代码:
import matplotlib.pyplot as plt
#
# list3 is list of data
plt.hist(list3, bins=10)
plt.xlabel('X')
plt.ylabel('Y')
fig.savefig('plot.png')问题是即使我没有调用plt.figure(),图形窗口还是出现了。有没有办法抑制图形图形窗口并将绘图保存到文件中?
发布于 2021-04-21 23:02:30
plt.savefig('plot.png')为我保存了png文件。您可能需要提供文件的完整路径
https://stackoverflow.com/questions/67198147
复制相似问题