[英]save multiple histograms in folder from a python code
我有一个循环来用python生成数百万个直方图,我需要将它们全部存储在我的笔记本电脑的一个文件夹中,有没有一种方法可以保存它们,而不必每次生成直方图时都按保存按钮?
谢谢
如果您使用的是matplotlib
,那么您要找的是plt.savefig()
。 该文档位于此处: http : //matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.savefig
例如:
import matplotlib.pyplot as plt
import numpy as np
# Some random data:
x = np.random.rand(100)
fig = plt.figure(1) # create a figure instance
ax = fig.add_subplot(111) # and axes
ax.hist(x) # plot the histogram
# plt.show() # this would show the plot, but you can leave it out
# Save the figure to the current path
fig.savefig('test_image.png')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.