子图matplotlib

时间:2019-04-02 23:27:54

标签: matplotlib

我有一个带有网格(1X7)的子图。我正在尝试调整两个子图之间的间距。

我在指定了左右间距的情况下使用了subplots_adjust选项。但这似乎不起作用。以下是子图的主要代码

fig, axs = plt.subplots(1,7,sharey=True,figsize=(12,10))
fig.subplots_adjust(left= 0.1, right=0.9, bottom = 0.1, top = 0.9, wspace=0.2) 
cs = axs[0].contour(xx,yy,tm_true.T, 40, cmap='inferno', interpolation='bilinear')
axs[0].text(0.4, -0.04, '(a)', transform=axs[0].transAxes, fontsize=16, fontweight='bold', va='top')

cs = axs[1].contour(xx,yy,tm_romgp.T, 40, cmap='inferno', interpolation='bilinear')
axs[1].text(0.4, -0.04, '(b)', transform=axs[1].transAxes, fontsize=16, fontweight='bold', va='top')

cs = axs[2].contour(xx,yy,tm_s1.T, 40, cmap='inferno', interpolation='bilinear')
axs[2].text(0.4, -0.04, '(c)', transform=axs[2].transAxes, fontsize=16, fontweight='bold', va='top')

cs = axs[3].contour(xx,yy,tm_e1.T, 40, cmap='inferno', interpolation='bilinear')
axs[3].text(0.4, -0.04, '(d)', transform=axs[3].transAxes, fontsize=16, fontweight='bold', va='top')

cs = axs[4].contour(xx,yy,tm_l1.T, 40, cmap='inferno', interpolation='bilinear')
axs[4].text(0.4, -0.04, '(e)', transform=axs[4].transAxes, fontsize=16, fontweight='bold', va='top')

cs = axs[5].contour(xx,yy,tm_b21.T, 40, cmap='inferno', interpolation='bilinear')
axs[5].text(0.4, -0.04, '(f)', transform=axs[5].transAxes, fontsize=16, fontweight='bold', va='top')

cs = axs[6].contour(xx,yy,tm_b31.T, 40, cmap='inferno', interpolation='bilinear')
axs[0].text(0.4, -0.04, '(g)', transform=axs[6].transAxes, fontsize=16, fontweight='bold', va='top')

fig.tight_layout() 

fig.subplots_adjust(bottom=0.08)

cbar_ax = fig.add_axes([0.22, -0.05, 0.6, 0.04])
fig.colorbar(cs, cax=cbar_ax, orientation='horizontal')
plt.show()

fig.savefig("temp_twoleg.png", bbox_inches = 'tight')
```[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/JFRkt.png

1 个答案:

答案 0 :(得分:1)

由于tight_layout将覆盖子图参数的所有设置,因此在tight_layout之后调用subplots_adjust毫无意义。最简单的方法就是从脚本中删除tight_layout行。