0

所以我在 Python 2.7.5 :: Anaconda 1.7.0 (64-bit) 中使用 matlibplot 我的 matlibplot.rc 文件中唯一未注释的行是:

figure.figsize   : 10, 5    # figure size in inches
figure.dpi       : 80      # figure dots per inch  
figure.facecolor : 1   # figure facecolor; 0.75 is scalar gray  
savefig.dpi         : 80      # figure dots per inch  
savefig.facecolor   : white    # figure facecolor when saving  

如果我打电话:

plt.savefig(name, bbox_inches=0)  
plt.show()  

一切正常

节目输出:

savefig 的输出:

但是,如果我简单地注释掉显示行,相同的文件看起来像这样:

这是怎么回事???我怎样才能解决这个问题?

4

1 回答 1

0

It's likely that previous figures are being overlaid on the current figure, especially if you have hold on.

Two simple ways to fix this:

Toggle hold before plotting to clear the graph:

pylab.hold(False) # clears graph
pylab.hold(True) # restores to state you want

Or explicitly clear the graph after saving:

pylab.save(...)
pylab.close()

The reason you don't see this behaviour with show is that there is an implicit close called when you close the figure which appears.

于 2013-10-23T01:11:17.460 回答