我在写一个快速而肮脏的脚本来即时生成绘图。我使用下面的代码(从Matplotlib文档)为起点:将绘图保存为图像文件,而不是使用Matplotlib显示它
from pylab import figure, axes, pie, title, show
# Make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
explode = (0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor': '0.8', 'pad': 5})
show() # Actually, don't show, just save to foo.png
我不想在GUI上显示的情节,相反,我想情节保存到一个文件(比如说FOO例如,它可以在批处理脚本中使用。我怎么做?
看起来像我找到了答案:其pylab.savefig( 'foo.png') – 2012-03-08 17:42:51
链接也许应该链接到某处matplotlib.org? – 2015-12-10 19:40:41
如果不使用pylab,图形对象也有一个'savefig'方法。所以你可以调用'fig = plt.figure()'然后'fig.savefig(...)'。 – 2015-12-10 19:43:10