在Matplotlib中调整图形质量

在Matplotlib中调整图形质量,第1张

在Matplotlib中调整图形质量

您的问题是先显示它,然后将其保存在GUI窗口中。您必须从

savefig
定义dpi的命令中保存图像。

像这样:

import matplotlib.pyplot as plt#First normal figurefig, axarr = plt.subplots(2,2, figsize=(6,6))for i,ax in enumerate(axarr.flatten()):    ax.plot(range(10))    ax.set_title('title'+str(i), fontsize=10)    ax.set_xlabel('x'+str(i), fontsize=10)    ax.set_ylabel('y'+str(i), fontsize=10)plt.tight_layout()plt.savefig('myfigure_100.png', dpi=100)plt.savefig('myfigure_200.png', dpi=200)

如果要显示它,可以在scrpit的末尾添加

plt.show()

编辑

图形大小的dpi与字体大小的关系可以在以下示例中显示:

import matplotlib.pyplot as plt#First normal figurefig1, axarr1 = plt.subplots(2,2, figsize=(6,6), dpi=100)for i,ax in enumerate(axarr1.flatten()):    ax.plot(range(10))    ax.set_title('title'+str(i), fontsize=10)    ax.set_xlabel('x'+str(i), fontsize=10)    ax.set_ylabel('y'+str(i), fontsize=10)plt.tight_layout()fig2, axarr2 = plt.subplots(2,2, figsize=(12,12), dpi=50)for i,ax in enumerate(axarr2.flatten()):    ax.plot(range(10))    ax.set_title('title'+str(i), fontsize=20)    ax.set_xlabel('x'+str(i), fontsize=20)    ax.set_ylabel('y'+str(i), fontsize=20)plt.tight_layout()plt.show()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5661983.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存