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

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

问题描述

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

How can I save Python plots at very high quality?

也就是说,当我不断放大保存在 PDF 文件中的对象时,为什么没有任何模糊?

That is, when I keep zooming in on the object saved in a PDF file, why isn't there any blurring?

另外,保存它的最佳模式是什么?

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

png, eps?还是其他?我不能做 pdf,因为有一个隐藏的数字发生在 Latexmk 编译中.

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

推荐答案

如果你使用的是 Matplotlib 并试图在 LaTeX 文档中获得好的数字,另存为 EPS.具体来说,在运行命令绘制图像后尝试这样的操作:

If you are using Matplotlib and are 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')

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

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

要在保存之前指定图形的方向,只需在 plt.savefig 调用之前调用以下命令,但在创建绘图之后(假设您使用名称为 的轴进行绘图斧头):

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)

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

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).

我发现最容易确定这些值的方法是首先绘制图像,然后旋转它并观察当前角度值出现在窗口底部,就在实际绘图下方.请记住,默认情况下会显示 x、y、z 位置,但是当您开始单击+拖动+旋转图像时,它们会替换为两个角度.

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 they are replaced with the two angles when you start to click+drag+rotate the image.

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

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