Python XArray刻度标签大小问题 [英] python xarray tick label size issue

查看:279
本文介绍了Python XArray刻度标签大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是xarray和cartopy的新手.我想问一下如何在x-/y-刻度上增加/减少标签大小. 以下是我的代码.

I am new for xarray and cartopy. I want to ask how can I increase/decrease labelsize on x-/y- ticks. Following is my code.

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来设置标签大小,但是字体的大小仍处于默认大小.同时,有人可以告诉我如何将颜色条标签移动到颜色条标题吗?

I have added tick_params to set up the labelsize, but the size of the font is still in the default size. Meanwhile, could anyone tell me how to move colorbar label to colorbar title?

谢谢

推荐答案

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

The fontsize of the tick labels can be set by passing a style dictionary to the Gridliner in a similar way you have toggled the top and right labels:

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

这将导致您的代码如下:

This results in the your code looking like:

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()

应生成如下所示的图(减去数据):

Which should produce a plot looking like this (minus the data):

实际上,Cartopy中的GeoAxis 应该处理ax.tick_params('both', labelsize=30),但似乎在生成标签时不会向下传递.随时在 Cartopy GitHub存储库上提出问题,开发人员社区可以在其中修复该问题.或通过提交拉取请求自行修复它!

In reality the GeoAxis in Cartopy should handle ax.tick_params('both', labelsize=30), but it seems that this is not passed down when the labels are generated. Feel free to raise an issue on the Cartopy GitHub repository where the community of developers can fix it. Or have a go at fixing it yourself by submitting a pull request!

这篇关于Python XArray刻度标签大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆