当我使用 show() 在 X 中绘制图形时,图形看起来非常好.但是,当我开始使用 savefig() 生成大量图形时,savefig() 生成的图形' 字体、线条、多边形看起来都比 show() 生成的图形小.我的环境是 Ubuntu,show() 的后端是 Qt4Agg.如何使 show() 图和 savefig() 图看起来一致?
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 指定保存图形的 DPI(如果没有在 .matplotlibrc 中指定,则默认为 100,看看dpi kwarg 到 savefig).它没有从原始图形的 DPI 中继承它.
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.
DPI 影响文本的相对大小和线条上笔划的宽度等.如果您希望事情看起来相同,则将 fig.dpi 传递给 fig.savefig.
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.
例如
import matplotlib.pyplot as plt fig = plt.figure() plt.plot(range(10)) fig.savefig('temp.png', dpi=fig.dpi)更多推荐
matplotlib savefig() 绘图与 show() 不同
发布评论