Python - matplotlib中子图的大小问题

时间:2015-06-03 16:03:14

标签: python matplotlib subplot

我想在一个数字上代表不同的情节,但是当我试图保存时,这个数字太重要而我无法得到它...它会超出“边界”,如下所示: 我的代码是:

fig, axes = plt.subplots(nrows=1, ncols=3)
plt.tight_layout(pad=0.01, w_pad=2, h_pad=1.0)
ax1 = plt.subplot(131) # creates first axis
ax1.set_xticks([0,2000,500,1000,1500])
ax1.set_yticks([0,2000,500,1000,1500])
ax1.imshow(U,cmap='hot',extent=(X.min(),2000,Y.min(),2000));
ax1.set_title("$ Ux_{mes} \/ (pix)$")
ax2 = plt.subplot(132) # creates second axis
ax2.set_xticks([0,2000,500,1000,1500])
ax2.set_yticks([0,2000,500,1000,1500])
ax2.imshow(UU_mask,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
ax2.set_title("$Ux_{cal} \/ (pix)$")
ax3 = plt.subplot(133) # creates first axis
ax3.set_xticks([0,2000,500,1000,1500])
ax3.set_yticks([0,2000,500,1000,1500])
ax3.imshow(resU,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
ax3.set_title("$\mid Ux - Ux \mid \/ (pix)$ ")

plt.savefig('test.png')

enter image description here

1 个答案:

答案 0 :(得分:1)

fig.savefig可以调整它给出的数字填充。尝试像

这样的东西
plt.savefig('test.png',  bbox_inches='tight', pad_inches=0.1)