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

查看:38
本文介绍了在 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?

pngeps?还是别的?我不能做 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天全站免登陆