matplotlib savefig() 绘图与 show() 不同

编程入门 行业动态 更新时间:2024-10-11 07:29:24
本文介绍了matplotlib savefig() 绘图与 show() 不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我使用 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() 不同

本文发布于:2023-07-18 15:45:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1146360.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:matplotlib   savefig   show

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!