相关疑难解决方法(0)

在Matplotlib中调整图形质量

我已经编写了一些代码来在matplotlib中生成多面板图形。为了使图看起来更清晰,可以在文档中使用,我尝试增加dpi。但是,我发现这也改变了图形,字体,线条等的大小,如以下更简单的示例所示:

#First normal figure
fig, 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()

#Again, with higher dpi
fig, axarr = plt.subplots(2,2, figsize=(6,6), dpi=200)
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.show()
Run Code Online (Sandbox Code Playgroud)

在我的计算机上(使用matplotlib 1.4.3),第二个图形的尺寸较大且文本较大,因此y轴标签重叠。如果不使用plt.tight_layout(),子图轴的重叠也会更糟。显然,这在尝试制作更高质量的图形时无济于事。这是怎么回事,如何更改图形质量并保持图形外观不变?当我调整了子图参数,添加了颜色条和图例等时,是否有一种解决方案也能正常工作?在此先感谢您提供的任何帮助。

python matplotlib

2
推荐指数
1
解决办法
2861
查看次数

标签 统计

matplotlib ×1

python ×1