我正在写一个快速而肮脏的脚本来动态生成情节.我使用以下代码(来自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.png),以便在批处理脚本中使用.我该怎么做?