我是xarray和cartopy的新手。我想问一下如何在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来设置标签大小,但是字体的大小仍然处于默认大小。同时,有人可以告诉我如何将颜色条标签移动到颜色条标题吗?
谢谢
答案 0 :(得分:1)
可以通过将样式字典传递到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上提出问题,开发者社区可以解决该问题。或通过提交拉取请求自行修复它!