matplotlib savefig()与show()不同 [英] matplotlib savefig() plots different from show()

查看:1472
本文介绍了matplotlib savefig()与show()不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 show()来绘制 X 中的图时,图看起来非常好。但是,当我开始使用 savefig()生成大量图时, savefig()生成的图
'字体,线条,多边形看起来都小于 show()生成的图形。我的环境是Ubuntu,并且 show()的后端是 Qt4Agg 。我该如何制作 show()图并且 savefig()图看起来一致?

解决方案

savefig 指定保存图形的DPI(如果未指定你的.matplotlibrc,看看 dpi kwarg to savefig )。它不会从原始图形的DPI中插入。



DPI影响文本的相对大小和线条上的笔画宽度等。如果您希望看起来完全相同,然后将 fig.dpi 传递给 fig.savefig





  import matplotlib.pyplot as plt 

fig = plt。 figure()
plt.plot(range(10))
fig.savefig('temp.png',dpi = fig.dpi)


When I use show() to plot the graphs in X, the graphs looks very good. However when I start to use savefig() to generate large amount of graphs, the savefig() generated graphs ' font, lines, polygons all look smaller than the show() generated graph. My environment is Ubuntu and the backend for show() is Qt4Agg. How can I make the show() plot and the savefig() plot looks consistent?

解决方案

savefig specifies the DPI for the saved figure (The default is 100 if it's not specified in your .matplotlibrc, have a look at the dpi kwarg to savefig). It doesn't inheret it from the DPI of the original figure.

The DPI affects the relative size of the text and width of the stroke on lines, etc. If you want things to look identical, then pass fig.dpi to fig.savefig.

E.g.

import matplotlib.pyplot as plt

fig = plt.figure()
plt.plot(range(10))
fig.savefig('temp.png', dpi=fig.dpi)

这篇关于matplotlib savefig()与show()不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆