约束_layout = true移动一列更深
我多次使用 constrained_layout= True ,一切正常...现在我添加了第二个 Colorbar,我得到了类似的东西:
我该如何解决这个问题?我希望条形和图之间具有相同的高度和间距。
colorbar_shrink = 0.6
pad=-0.15
fig, axarr = plt.subplots(nrows=2, ncols=2, figsize=(15, 10), constrained_layout=True,
sharey=True, subplot_kw={'projection': crs})
# fig.tight_layout()
# fig.subplots_adjust(wspace=0.01)
# fig.set_constrained_layout_pads(w_pad=0.02, h_pad=0.02, hspace=-0.2,
# wspace=0.2)
fig.suptitle('Bla', y=1.01)
# fig.set_constrained_layout_pads(w_pad=0, h_pad=0.05,hspace=0.1, wspace=0.2)
axlist = axarr.flatten()
for ax in axlist:
plot_background(ax)
print('First .')
levels = np.linspace(0, 2, 10)
cf1 = axlist[0].contourf(lon_2d, lat_2d, aod_dust_550nm, cmap='Oranges',
transform=ccrs.PlateCarree(), zorder=0, levels=levels, extend='both')
cf2 = axlist[0].contourf(lon_2d, lat_2d, tq, cmap='Blues', vmin=0.0001, vmax=10 ,
levels=tq_lev, norm=matplotlib.colors.LogNorm(),
transform=ccrs.PlateCarree(), zorder=0, extend='max')
cb1 = fig.colorbar(cf1, ax=axlist[0], orientation='horizontal', format='%.1f',
shrink=colorbar_shrink, pad=pad)
cb2 = fig.colorbar(cf2, ax=axlist[0], orientation='vertical', #format='%.4f',
shrink=colorbar_shrink)
cb1.set_label('Dust optical depth @550nm',labelpad=-45, fontsize=12)
cb2.ax.set_ylabel('TQ in kg m$^{-2}$')
cb2.formatter = LogFormatter()
cb2.set_ticks([1e-4,1e-3, 1e-2, 1e-1, 1e0, 10])
cb2.update_ticks()
print('Second..')
# Upper right plot - Wind and Windspeed
levels = np.linspace(0.0, 50.0, 50)
cf2 = axlist[1].contourf(lon_2d, lat_2d, windspeed_900, levels=levels,
cmap='jet', transform=ccrs.PlateCarree() ,zorder=0, extend='max')
#Every n-th quiver
wind_slice = (slice(None, None, 15), slice(None, None, 15))
c2 = axlist[1].quiver(lon_2d[wind_slice], lat_2d[wind_slice] ,
u_300.values[wind_slice] , v_300.values[wind_slice],
color='black', transform=ccrs.PlateCarree())
cb2 = fig.colorbar(cf2, ax=axlist[1], orientation='horizontal',format='%i',
shrink=colorbar_shrink)#, pad=paddy)
cb2.set_label('Wind speed in m s-1 @900hPa',labelpad=-45, fontsize=12)
plt.quiverkey(c2, 0.99, -0.16, 10,'velocity (10 m s$^{-1}$)',
labelpos='W',transform=ccrs.PlateCarree(), color='r')
# plt.show()
多谢。
I used constrained_layout= True multiple times and everything worked good... now I added a second Colorbar an i get somthing like that:
How I can fix this? I want the same hight and space between the bars and plots.
colorbar_shrink = 0.6
pad=-0.15
fig, axarr = plt.subplots(nrows=2, ncols=2, figsize=(15, 10), constrained_layout=True,
sharey=True, subplot_kw={'projection': crs})
# fig.tight_layout()
# fig.subplots_adjust(wspace=0.01)
# fig.set_constrained_layout_pads(w_pad=0.02, h_pad=0.02, hspace=-0.2,
# wspace=0.2)
fig.suptitle('Bla', y=1.01)
# fig.set_constrained_layout_pads(w_pad=0, h_pad=0.05,hspace=0.1, wspace=0.2)
axlist = axarr.flatten()
for ax in axlist:
plot_background(ax)
print('First .')
levels = np.linspace(0, 2, 10)
cf1 = axlist[0].contourf(lon_2d, lat_2d, aod_dust_550nm, cmap='Oranges',
transform=ccrs.PlateCarree(), zorder=0, levels=levels, extend='both')
cf2 = axlist[0].contourf(lon_2d, lat_2d, tq, cmap='Blues', vmin=0.0001, vmax=10 ,
levels=tq_lev, norm=matplotlib.colors.LogNorm(),
transform=ccrs.PlateCarree(), zorder=0, extend='max')
cb1 = fig.colorbar(cf1, ax=axlist[0], orientation='horizontal', format='%.1f',
shrink=colorbar_shrink, pad=pad)
cb2 = fig.colorbar(cf2, ax=axlist[0], orientation='vertical', #format='%.4f',
shrink=colorbar_shrink)
cb1.set_label('Dust optical depth @550nm',labelpad=-45, fontsize=12)
cb2.ax.set_ylabel('TQ in kg m$^{-2}
THanks a lot.
)
cb2.formatter = LogFormatter()
cb2.set_ticks([1e-4,1e-3, 1e-2, 1e-1, 1e0, 10])
cb2.update_ticks()
print('Second..')
# Upper right plot - Wind and Windspeed
levels = np.linspace(0.0, 50.0, 50)
cf2 = axlist[1].contourf(lon_2d, lat_2d, windspeed_900, levels=levels,
cmap='jet', transform=ccrs.PlateCarree() ,zorder=0, extend='max')
#Every n-th quiver
wind_slice = (slice(None, None, 15), slice(None, None, 15))
c2 = axlist[1].quiver(lon_2d[wind_slice], lat_2d[wind_slice] ,
u_300.values[wind_slice] , v_300.values[wind_slice],
color='black', transform=ccrs.PlateCarree())
cb2 = fig.colorbar(cf2, ax=axlist[1], orientation='horizontal',format='%i',
shrink=colorbar_shrink)#, pad=paddy)
cb2.set_label('Wind speed in m s-1 @900hPa',labelpad=-45, fontsize=12)
plt.quiverkey(c2, 0.99, -0.16, 10,'velocity (10 m s$^{-1}$)',
labelpos='W',transform=ccrs.PlateCarree(), color='r')
# plt.show()
THanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论