- 积分
- 59
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2021-11-1
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
只出了第一模态的图,后面的图没出来
hgt = xr.open_dataset(r"D:\python\hgt.mon.mean.nc").hgt.loc["1991-01-01":"2020-12-31",'500',70:20,40:140]
hgt_ano=hgt.loc[hgt.time.dt.month==1]-hgt.loc[hgt.time.dt.month==1].mean('time')
llat = np.array(hgt_ano.lat)
coslat =np.cos(np.deg2rad(llat))#b度权重
wgts =np.sqrt(coslat)[...,np.newaxis]#加权
solver = Eof(hgt_ano.values, weights=wgts)#加权eof
eof = solver.eofsAsCorrelation(neofs=3)#做前3个模态
pc = solver.pcs(npcs=3, pcscaling=1)#方差
var = solver.varianceFraction(neigs=3)
color1=[]
color2=[]
color3=[]
for i in range(len(hgt_ano.time)):
if pc[i,0] >=0:
color1.append('indianred')
elif pc[i,0]<0:
color1.append('teal')
if pc[i,1]>=0:
color2.append('indianred')
elif pc[i,1]<0:
color2 .append('teal')
if pc[i,2]>=0:
color3. append('indianred')
elif pc[i,2]<0:
color3 .append('teal')
def eof_draw(ax,data,eofs,title,levels,colors,lon,lat):
lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax[0].coastlines('110m')
ax[0].set_extent([40,140,20,70], crs=ccrs.PlateCarree())
ax[0].set_xticks([40,70,100,130], crs=ccrs.PlateCarree())
ax[0].set_yticks([30,50,70], crs=ccrs.PlateCarree())
C1=ax[0].contourf(lon[::],lat[::],data[0][eofs],
levels=levels,extend='both',cmap="RdBu_r",
transform=ccrs.PlateCarree())#画填色图
ax[0].xaxis.set_major_formatter(lon_formatter)#修改经纬度表达形式
ax[0].yaxis.set_major_formatter(lat_formatter)
ax[0].set_title(title[0],loc='left',fontweight='heavy')
ax[0].set_title('%.2f%%' % (var[eofs]*100),loc='right',fontweight='heavy')
ax[1].set_title(title[1],loc='left',fontweight='heavy')
ax[1].axhline(0,linestyle="--")
ax[1].bar(np.arange(data[1].shape[0]),data[1][:,eofs],color=colors)
ax[1].set_xticks(np.arange(1,data[1].shape[0],5))
ax[1].set_xticklabels(np.arange(1980,2020+5,5))
return C1
plt.rcParams['font.sans-serif']='Times New Roman'
plt.style.use('seaborn')
mpl.rc('font',size=20,weight='normal')#设理全局字体大小
fig = plt.figure(figsize=(15,15))
proj = ccrs.PlateCarree(central_longitude=200)
fig_ax1 = fig.add_axes([0.1,0.7,0.5,0.3],projection = proj)
fig_ax2 = fig.add_axes([0.1,0.35,0.5,0.3],projection = proj)
fig_ax3 = fig.add_axes([0.1,0.0,0.5,0.3],projection = proj)
fig_ax4 = fig.add_axes([0.1+0.55,0.725,0.47,0.25])
fig_ax5 = fig.add_axes([0.65,0.375,0.47,0.25])
fig_ax6 = fig.add_axes([0.65,0.025,0.47,0.25])
c1 = eof_draw([fig_ax1,fig_ax4],[eof,pc],0,["(a) EOF1","(b) PC1"],np.arange(-1,1.01,0.1),color1,hgt.lon,hgt.lat)
c2 = eof_draw([fig_ax2,fig_ax5],[-eof,-pc],1,["(c) EOF2", "(d) PC2"],np.arange(-1,1.01,0.1),color2,hgt.lon,hgt.lat)
c3 = eof_draw([fig_ax3,fig_ax6],[-eof,-pc],2,["(e) EOF3","(f) Pc3"],np.arange(-1,1.01,0.1),color3,hgt.lon,hgt.lat)
cax = plt.axes([0.1,-0.05,1,0.02])
cbar=plt.colorbar(c1,cax=cax, orientation='horizontal')
|
|