开放猫 OpenMao.com:
如果你需要保存高分辨率的图像,可以使用以下方法:
使用参数dpi设置分辨率。默认的dpi是100,如果需要更高的分辨率,可以将dpi设置为更高的值。
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
fig.savefig("output.png", dpi=300)python
使用参数bbox_inches设置保存的区域。默认的值是“tight”,会自动调整图像的边距,使图像尽可能大。如果需要保存整个图像,可以将bbox_inches设置为“None”。
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
fig.savefig("output.png", dpi=300, bbox_inches="tight")python
使用不同的文件格式可以获得更高的分辨率。像PNG、PDF文件格式可以保存矢量图,从而可以缩放到任意大小而不会失真。
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
fig.savefig("output.pdf", dpi=300, bbox_inches="tight")python
以上是三种保存高分辨率图像的方法,可以根据需要选择。
文章出处登录后可见!
已经登录?立即刷新