python xarray tick label size issue

纵饮孤独 提交于 2019-12-11 13:44:13

问题


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

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?

Thanks


回答1:


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

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!



来源:https://stackoverflow.com/questions/52936720/python-xarray-tick-label-size-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!