Python保存后图片双坐标显示不全

保存时图片不完整的问题

在plt.savefig中加入bbox_inches='tight’参数设置

fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(12,6), tight_layout=True)
labels = ['2022-{}-01'.format(str(i).zfill(2)) for i in range(1,13)]
y1 = np.random.randint(low=1, high=10, size=12)
y2 = np.random.randint(low=1, high=10, size=12)
axes[0].bar(labels, y1)
axes[0].set_xticks(labels)
axes[0].set_xticklabels(labels, rotation=75)
axes[1].bar(labels, y2)
axes[1].set_xticks(labels)
axes[1].set_xticklabels(labels, rotation=75)
plt.savefig('test.png', dpi=600, bbox_inches='tight')
# savefig时加入bbox_inches='tight'参数设置

在这里插入图片描述

参考文献:https://www.jb51.net/article/253711.htm

猜你喜欢

转载自blog.csdn.net/weixin_39559994/article/details/129188826