在不改变大小的情况下增加matplotlib图表中的dpi [英] Increase dpi in matplotlib chart without changing it's size

查看:94
本文介绍了在不改变大小的情况下增加matplotlib图表中的dpi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Python 的 reportlab 模块创建 pdf.我使用matplotlib生成了png,并使用报告实验室的canvas.drawImage方法将其保存在pdf文件中.我的问题是生成的png文件很模糊.我用 plt.figure(figsize=(20,10)) 指定了以英寸为单位的尺寸,并用 plt.savefig 方法保存了图片.
这很完美(除了图片的模糊质量).
但是当我在 savefig 方法中增加 dpi 时,图片的大小会增加.
有什么方法可以提高dpi而不改变图片大小.还是有办法将其调整为预定义的值?

I'm trying to create a pdf using Python's reportlab module. I generated a png with matplotlib and saved it in the pdf file using report labs canvas.drawImage method. My problem is that the generated png file is very fuzzy. I specified the size in inches with plt.figure(figsize=(20,10)) and saved the picture with the plt.savefig method.
This works out perfectly (except the fuzzy quality of the picture).
But when I increase the dpi within the savefig method the size of the picture increases.
Is there any way to improve the dpi without changing the picture size. Or is there a way to resize it to the predefined values?

谢谢!

推荐答案

f = df.plot()
fig = f.get_figure()
fig.set_size_inches((2,2))
fig.savefig('C:/temp/foo.png', bbox_inches='tight', dpi=1500)

这篇关于在不改变大小的情况下增加matplotlib图表中的dpi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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