使用 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}$)')

This is the output: Maps of crop biomass for two irrigations (1 and 2) and four scen_new levels (0,1,2,3)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...