Increase dpi in matplotlib chart without changing it's size

筅森魡賤 提交于 2021-02-11 14:31:51

问题


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?

Thanks!


回答1:


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


来源:https://stackoverflow.com/questions/53821417/increase-dpi-in-matplotlib-chart-without-changing-its-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!