如何解决使用 xarray 数据集重新排序在带有子图的图中绘制的行序列
我正在尝试使用 xarray 重新排列绘图中的行序列。分配给该行的变量是 scen_new 并且有 4 个级别(0、1、2、3)。代码按升序绘制它。我想绘制一个特定的订单或行:0、2、3、1。你知道怎么做吗?我也尝试过使用“row_order”,但没有奏效。
Here is the structure of my xarray dataset (data2)
#Plotting mean biomass
a = df.groupby(['irr','lat','lon','cultivar'],as_index=False).mean()
map_proj = ccrs.Mercator(central_longitude=-95)
p = data2.biomass.mean(dim=('time'),skipna=True).plot(x='lon',y='lat',col='irr',row='scen_new',transform=ccrs.PlateCarree(central_longitude=0),subplot_kws={'projection': map_proj},vmin=a.biomass.quantile(0.001),vmax=a.biomass.quantile(0.999),figsize=(10,16),#rasterized=True
# The remaining kwargs customize the plot just as for not-faceted plots
robust=True,cmap=mpl.cm.RdYlGn,cbar_kwargs={
"orientation": "vertical","shrink": 0.7,"aspect": 25,"pad": 0.05,#distance of colorbar to plot
"label": "Biomass ($kg\,ha^{-1}$)"},zorder=1,add_colorbar=False,label=False)
def area(ax,iso,clr) :
shp = shpreader.natural_earth(resolution='10m',category='cultural',name='admin_0_countries')
reader = shpreader.Reader(shp)
for n in reader.records() :
if n.attributes['ADM0_A3'] == iso:
ax.add_geometries(n.geometry,ccrs.PlateCarree(),facecolor=clr,alpha = 1.00,linewidth =0.01,edgecolor = "white",label=n.attributes['ADM0_A3'])
return ax
iso3 = ['CAN','MEX']
for value in iso3 :
area(ax,value,"white")
for ax in p.axes.flat:
gl = ax.gridlines(crs=ccrs.PlateCarree(),linewidth=0.01,color='w',alpha=0,linestyle='-',draw_labels=False,dms=True,x_inline=False,y_inline=False)
ax.add_feature(cfeature.COASTLINE,color='k')
ax.add_feature(cfeature.STATES,linewidth=0.1,zorder=3)
ax.add_feature(cfeature.OCEAN,color='white',zorder=2)
ax.add_feature(cfeature.LAKES,zorder=1.5)
ax.add_feature(cfeature.BORDERS,color='grey')
ax.set_extent([-125,-75,25.3,46.5],crs=ccrs.PlateCarree())
ax.outline_patch.set_visible(False)
gl.xlabels_top = False
gl.ylabels_right = False
area(ax,"white")
#Adjust colorbar and subplots
plt.subplots_adjust(wspace=0.05,hspace=-0.75)
p.add_colorbar(orientation='vertical',pad=0.04,shrink=0.4,aspect=25,label='Mean Biomass ($kg\,ha^{-1}$)')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。