【发布时间】:2021-05-31 12:25:26
【问题描述】:
我正在绘制 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 以使图之间的宽度更小,但是添加该行时没有区别。 如何使这些图更紧密地结合在一起并使数字更大?颜色条也重叠在图像上,为什么会发生这种情况?
【问题讨论】:
-
“问题”之一是投影迫使绘图具有一定的纵横比。为了适应具有该纵横比的给定高度(以避免使地图变形),它们的宽度需要相当小。你可以试试
figsize=(15,44)。也许增加列数? -
wspace=None不会做任何事情。试试wspace=0。但正如@JohanC 所说,你的地块的纵横比是固定的,你的图形宽度是固定的,所以空间必须去某个地方。要获得更好的颜色条行为,您可以使用constrained_layout而不是tight_layout。
标签: python numpy matplotlib jupyter subplot