Python - 三色情况下的 matplotlib 子图

Python - matplotlib subplots in tripcolor case

我正在尝试组织和调整使用 tripcolor od Delaunay 三角剖分获得的三个子图。问题是我不能使用函数:plt.tight_layout(pad=0.5, w_pad=2.5, h_pad=2.0) 来设置 windows 大小,它在这不起作用案件。 结果对应于:

我想要 windows 的正方形...我的代码是:

import matplotlib.tri as tr
triang = tr.Triangulation(Xini, Yini)   

xmid = Xini[triang.triangles].mean(axis=1)
ymid = Yini[triang.triangles].mean(axis=1)

plt.figure()

ax1 = plt.subplot(131) # creates first axis
i1 =ax1.tripcolor(triang, Epst_eq2, shading='flat', cmap=plt.cm.hot)
ax1.set_xlim([-2.5,2.5])
ax1.set_ylim([-2.5,2.5])
# plt.title('tripcolor of Delaunay triangulation, flat shading')
plt.colorbar(i1,ax=ax1,ticks=np.linspace(0,0.005,3))

ax2 = plt.subplot(132) # creates first axis
ax2.tripcolor(triang, Epst_eq3, shading='flat', cmap=plt.cm.hot)
ax2.set_xlim([-2.5,2.5])
ax2.set_ylim([-2.5,2.5])

ax3 = plt.subplot(133) # creates first axis

ax3.tripcolor(triang, Epst_eq4, shading='flat', cmap=plt.cm.hot)

ax3.set_xlim([-2.5,2.5])
ax3.set_ylim([-2.5,2.5])

plt.savefig('test2.png',dpi=100)
plt.show()

终于用上了gridspec,可以轻松修改大小了!

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

fig = plt.figure(figsize=(16, 6)) 

gs = gridspec.GridSpec(1, 3,width_ratios=[1.2,1,1])

ax1 = plt.subplot(gs[0])
i1 =ax1.tripcolor(triang, Epst_eq2, shading='flat', cmap=plt.cm.hot)
ax1.set_xlim([-2.5,2.5])
ax1.set_ylim([-2.5,2.5])
# plt.title('tripcolor of Delaunay triangulation, flat shading')
plt.colorbar(i1,ax=ax1,ticks=np.linspace(0,0.005,3))

ax2 = plt.subplot(gs[1])
ax2.tripcolor(triang, Epst_eq3, shading='flat', cmap=plt.cm.hot)
ax2.set_xlim([-2.5,2.5])
ax2.set_ylim([-2.5,2.5])

ax3 = plt.subplot(gs[2])
ax3.tripcolor(triang, Epst_eq4, shading='flat', cmap=plt.cm.hot)
ax3.set_xlim([-2.5,2.5])
ax3.set_ylim([-2.5,2.5])

plt.tight_layout()
plt.savefig('test2.png',dpi=100)
plt.show()