以非常高的质量在python中保存图像 [英] saving images in python at a very high quality

查看:98
本文介绍了以非常高的质量在python中保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以非常高的质量保存Python图?



也就是说,当我不断放大保存在pdf文件中的对象时,没有模糊?



另外,什么才是最好的模式保存?



png eps ?还是其他的?我不能这样做 pdf ,因为有一个隐藏的数字发生在 Latexmk 编译的混乱之处。

如果你正在使用 matplotlib 并试图在乳胶文档中获得好的数字,那么你可以使用

解决方案保存为eps。具体来说,在运行命令来绘制图像后,尝试类似这样的操作:

  plt.savefig('destination_path.eps',format ='eps',dpi = 1000)

我发现eps文件效果最好, dpi 参数是真正让它们在文档中看起来不错的原因。



更新:



要在保存之前指定图的方向,只需在 plt.savefig 调用之前调用以下内容,但在创建图之后(假设您已使用一个名为 ax 的轴:

  ax.view_init = elevation_angle,azim = azimuthal_angle)

其中 elevation_angle 是指定极角(从垂直z轴向下)的数字(以度为单位), azimuthal_angle 指定方位角(围绕z轴)。



我发现用f来确定这些值是最简单的首先绘制图像,然后旋转它,观察角度的当前值,然后在实际绘图下方的窗口底部出现。请记住,默认情况下,x,y,z的位置出现,但当您开始点击+拖动并旋转图像时,会被两个角度替换。


How can I save python plots at very high quality?

That is, when I keep zooming in on the object saved in a pdf file, there is no blurring?

Also, what would be the best mode to save it in?

png, eps? Or some other? I can't do pdf because there is a hidden number that happens that mess with Latexmk compilation.

解决方案

If you are using matplotlib and trying to get good figures in a latex document, save as an eps. Specifically, try something like this after running the commands to plot the image:

plt.savefig('destination_path.eps', format='eps', dpi=1000)

I have found that eps files work best and the dpi parameter is what really makes them look good in a document.

UPDATE:

To specify the orientation of the figure before saving simply call the following before the plt.savefig call, but after creating the plot (assuming you have plotted using an axes with the name ax):

ax.view_init(elev=elevation_angle, azim=azimuthal_angle)

Where elevation_angle is a number (in degrees) specifying the polar angle (down from vertical z axis) and the azimuthal_angle specifies the azimuthal angle (around the z axis).

I find that it is easiest to determine these values by first plotting the image and then rotating it and watching the current values of the angles appear towards the bottom of the window just below the actual plot. Keep in mind that the x, y, z, positions appear by default, but are replaced with the two angles when you start to click+drag+rotate the image.

这篇关于以非常高的质量在python中保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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