您如何改善matplotlib图像质量? [英] How do you improve matplotlib image quality?

查看:281
本文介绍了您如何改善matplotlib图像质量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python程序生成一些数据,使用matplotlib.pyplot绘制数据,然后在乳胶文件中显示该图.

I am using a python program to produce some data, plotting the data using matplotlib.pyplot and then displaying the figure in a latex file.

我当前正在将图形保存为.png文件,但是图像质量不是很好.我试过更改matplotlib.pyplot.figure(dpi=200)等中的DPI,但这似乎没有什么区别.我也尝试过使用differnet图像格式,但是它们看起来都有些褪色并且不是很清晰.

I am currently saving the figure as a .png file but the image quality isn't great. I've tried changing the DPI in matplotlib.pyplot.figure(dpi=200) etc but this seems to make little difference. I've also tried using differnet image formats but they all look a little faded and not very sharp.

还有其他人有这个问题吗?

Has anyone else had this problem?

任何帮助将不胜感激

推荐答案

您可以将图像保存为矢量格式,以便在不降低质量的情况下可缩放.此类格式为PDF和EPS.只需将扩展名更改为.pdf.eps,matplotlib将写入正确的图像格式.请记住,LaTeX喜欢EPS,PDFLaTeX喜欢PDF图像.尽管大多数现代LaTeX可执行文件都是伪装的PDFLaTeX并可以即时转换EPS文件(效果与在序言中包含epstopdf包一样,但效果可能不尽如人意).

You can save the images in a vector format so that they will be scalable without quality loss. Such formats are PDF and EPS. Just change the extension to .pdf or .eps and matplotlib will write the correct image format. Remember LaTeX likes EPS and PDFLaTeX likes PDF images. Although most modern LaTeX executables are PDFLaTeX in disguise and convert EPS files on the fly (same effect as if you included the epstopdf package in your preamble, which may not perform as well as you'd like).

或者,增加DPI,很多.这些是您应该记住的数字:

Alternatively, increase the DPI, a lot. These are the numbers you should keep in mind:

  • 300dpi:普通纸打印
  • 600dpi:专业纸张打印.大多数商用办公室打印机的输出结果都可以达到此目的.
  • 1200dpi:专业的海报/宣传册质量.

我将它们与figurefigsize选项结合使用,以调整PNG图形的质量,当您通过dpi提高质量时,该选项可以正确缩放文本和图形的大小.

I use these to adapt the quality of PNG figures in conjunction with figure's figsize option, which allows for correctly scaled text and graphics as you improve the quality through dpi.

这篇关于您如何改善matplotlib图像质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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