如何修复 plt.subplots 以使图更接近?

How do I fix plt.subplots to bring the plots closer together?

我正在绘制 27 张地图,或 9 行和 3 列。我正在使用 plt.subplots 绘制它们,但我正在努力将这些图拉近?我都试过了:

plt.tight_layout()  
fig.tight_layout()

但我每次添加时都会收到此错误:

ValueError: zero-size array to reduction operation minimum which has no identity

到目前为止,这是我使用 plt.subplot 和映射的代码,它似乎可以正常工作,但地图布局的可读性不是很好:

fig, axes = plt.subplots(nrows=9, ncols=3,  figsize=(60,44), subplot_kw=dict(projection=ccrs.PlateCarree()))
for i,t,ax in zip(range(27),time_years, axes.ravel()):
    ax.set_extent([-90, 10, 5, 85], crs=ccrs.PlateCarree())
    x = ax.contourf(longitude,latitude,yearly_means[i],10, extend='both')
    ax.add_feature(cfeature.LAND, zorder=100, edgecolor='k')
    ax.coastlines()
    gridlines = ax.gridlines(draw_labels=True)
    gridlines.xlabels_top = False
    gridlines.ylabels_right = False
    ax.text(.5,-.11, 'Longitude' , va='bottom' , ha='center', rotation='horizontal', rotation_mode= 'anchor',transform=ax.transAxes)
    ax.text(-.15, .5, 'Latitude' , va='bottom' , ha='center', rotation='vertical', rotation_mode= 'anchor',transform=ax.transAxes)
    ax.set_title('extremes for %d' %t)
cbar = fig.colorbar(x, orientation='horizontal', ax = axes,fraction=.046, pad=0.04)
cbar.set_label('psu', labelpad=15, y=.5, rotation=0)
#plt.tight_layout()
plt.subplots_adjust(wspace=None, hspace=None) # THIS DOES NOT WORK, no change
plt.show()  

我尝试添加:plt.subplots_adjust 使绘图之间的宽度更小,但是当我添加那条线时没有区别。 我如何将这些图拉近并使数字更大?颜色条也重叠在图像上,为什么会这样?

首先要尝试的是 plt.tight_layout() - 它会自动调整子图周围的填充。另一件可以玩的东西是 figsize 及其纵横比,以使其与您的子图对齐一致。在您的情况下,canvas 对于子图来说太宽了。