简体   繁体   中英

Python - Size problems with subplots in matplotlib

I want to represent different plots on a figure but when i try to save, the figure is too important and i cant get all it...it execeeds the "borders" as you can see below : My code is :

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')

在此处输入图片说明

fig.savefig can adjust the padding it gives the figure. Try something like

plt.savefig('test.png',  bbox_inches='tight', pad_inches=0.1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM