python xarray 刻度标签大小问题

python xarray tick label size issue

我是 xarray 和 cartopy 的新手。我想问一下如何 increase/decrease 在 x-/y- 刻度上标注尺寸。 以下是我的代码。

fig = plt.figure(figsize=(18,8)) 
ax  = plt.axes(projection =ccrs.PlateCarree())   
ax.add_feature(cartopy.feature.LAND,facecolor='wheat') 
ax.add_feature(cartopy.feature.OCEAN) 
ax.add_feature(cartopy.feature.STATES, linestyle='-',lw=1.0,edgecolor='white') 
ax.add_feature(cartopy.feature.BORDERS, linestyle='-',lw=2.5,edgecolor='white') 
gp = ds.isel(time=0).gpm.plot.pcolormesh('lon','lat',ax=ax,
             infer_intervals=True,vmin=0,vmax=1600,cmap='jet',extend='both') 
ax.coastlines(resolution='50m',color='white') 
ax.add_feature(cartopy.feature.RIVERS) 
gl = ax.gridlines(color='gray',alpha=0.6,draw_labels=True) 
gl.xlabels_top, gl.ylabels_right = False, False 
ax.yaxis.tick_right() 
ax.set_ylim([18,32]) 
ax.set_xlim([-100,-77])  
ax.set_title('GPM Accumulated Rain (12Z Aug24 - 12Z Aug31)', fontsize=16) 
ax.set_aspect('equal') 
ax.tick_params('both',labelsize=30) 
plt.show()       

我添加了tick_params来设置labelsize,但是字体大小还是默认大小。同时,谁能告诉我如何将颜色栏标签移动到颜色栏标题?

谢谢

可以通过将样式字典传递给 Gridliner 来设置刻度标签的字体大小,方法与切换顶部和右侧标签的方式类似:

gl.xlabel_style = {fontsize: 30}
gl.ylabel_style = {fontsize: 40}

这会使您的代码看起来像:

fig = plt.figure(figsize=(18,8)) 
ax  = plt.axes(projection =ccrs.PlateCarree())   
ax.add_feature(cartopy.feature.LAND,facecolor='wheat') 
ax.add_feature(cartopy.feature.OCEAN) 
ax.add_feature(cartopy.feature.STATES, linestyle='-',lw=1.0,edgecolor='white') 
ax.add_feature(cartopy.feature.BORDERS, linestyle='-',lw=2.5,edgecolor='white') 
gp = ds.isel(time=0).gpm.plot.pcolormesh('lon','lat',ax=ax,
             infer_intervals=True,vmin=0,vmax=1600,cmap='jet',extend='both') 
ax.coastlines(resolution='50m',color='white') 
ax.add_feature(cartopy.feature.RIVERS) 
gl = ax.gridlines(color='gray',alpha=0.6,draw_labels=True) 
gl.xlabels_top, gl.ylabels_right = False, False
gl.xlabel_style, gl.ylabel_style = {'fontsize': 30}, {'fontsize': 40}
ax.yaxis.tick_right() 
ax.set_ylim([18,32]) 
ax.set_xlim([-100,-77])  
ax.set_title('GPM Accumulated Rain (12Z Aug24 - 12Z Aug31)', fontsize=16) 
ax.set_aspect('equal') 
plt.show()

应该生成如下图(减去数据):

实际上 Cartopy 中的 GeoAxis 应该 处理 ax.tick_params('both', labelsize=30),但似乎在生成标签时并没有传递下来。请随时在 Cartopy GitHub repository 上提出问题,开发者社区可以在其中解决问题。或者尝试通过提交拉取请求自行修复它!