相关疑难解决方法(0)

将绘图保存到图像文件,而不是使用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
Run Code Online (Sandbox Code Playgroud)

我不想在GUI上显示绘图,相反,我想将绘图保存到文件(例如foo.png),因此,例如,它可以在批处理脚本中使用.我怎么做?

python plot matplotlib

1060
推荐指数
20
解决办法
144万
查看次数

标签 统计

matplotlib ×1

plot ×1

python ×1