- 积分
- 411
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2020-6-9
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 岫鹿森涌 于 2021-5-29 15:06 编辑
用AO指数回归得到1979-2017年5月地面降水场时,为什么填色图上是点状的呢?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
from scipy import stats
import os
import glob as glob
import xarray as xr
data=pd.read_csv('E:\\norm.daily.ao.index.b500101.current.ascii',header=None,sep='\s+',names=['year','month','day','ao'])
a = data.loc[10592:24837,['month','ao']] # 1979-2017年的月份和ao指数
b=a.ao[a.month==5] #5月的ao指数
#print(b)
c=np.zeros(39)
for i in range(0,1209,31):
c=c+sum(b[i:i+31]/31)
os.chdir('D:\\A\\data\\pdaily')
files2=glob.glob('*.nc')
xy=np.zeros((1,360,720))
for file in files2:
precip=xr.open_dataset(file)['precip'][120:151,:,:]
lon=xr.open_dataset(file)['lon']
lat=xr.open_dataset(file)['lat']
xy=np.append(xy,precip,axis=0)
xy1=xy[1:,:,:]
a=np.zeros((39,360,720),)
for i in range(0,39):
a[i,:,:]=np.mean(xy1[i*31:(i+1)*31,:,:],axis=0)
#print(a.shape)
#print(type(b))
#print(type(b[0]))
a[np.isnan(a)] = 0
#print(a)
slope, intercept, r_value, p_value, std_err = np.zeros((360,720)),np.zeros((360,720)),np.zeros((360,720)),np.zeros((360,720)),np.zeros((360,720))
for i in range(360):
for j in range(720):
slope[i,j], intercept[i,j], r_value[i,j], p_value[i,j], std_err[i,j] = stats.linregress(c,a[:,i,j])
#选择投影
proj = ccrs.PlateCarree(central_longitude=90)
#创建图形
fig = plt.figure(figsize=(12,8))
fig_ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.8],projection = proj)
#设置边界
leftlon, rightlon, lowerlat, upperlat = (0,120,-20,70)
img_extent = [leftlon, rightlon, lowerlat, upperlat]
fig_ax1.set_extent(img_extent, crs=ccrs.PlateCarree())
#绘制海岸线和湖泊等地理特征
fig_ax1.add_feature(cfeature.COASTLINE.with_scale('50m'))
fig_ax1.add_feature(cfeature.LAKES, alpha=0.5)
#设置刻度及刻度标签格式
fig_ax1.set_xticks(np.arange(leftlon,rightlon+30,20), crs=ccrs.PlateCarree())
fig_ax1.set_yticks(np.arange(lowerlat,upperlat+30,20), crs=ccrs.PlateCarree())
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
fig_ax1.xaxis.set_major_formatter(lon_formatter)
fig_ax1.yaxis.set_major_formatter(lat_formatter)
#绘制相关系数填色
cf1 = fig_ax1.contourf(lon,lat,slope, zorder=0, levels=np.arange(-8,8.1,0.1),extend = 'both',transform=ccrs.PlateCarree(), cmap=plt.cm.RdBu_r)
#绘制显著性打点。思路为将0-0.01范围内的区域用点的标记来填充,来表示显著性99%水平。
#cf2 = fig_ax1.contourf(lon,lat, p_value, [0,0.01,1] ,
# zorder=1,hatches=['...', None],colors="none", transform=ccrs.PlateCarree())
#色标
position=fig.add_axes([0.35, 0.03, 0.35, 0.025])
fig.colorbar(cf1,cax=position,orientation='horizontal',format='%.2f')
#显示
plt.savefig('D:\\A\\SFW\\figure\\5phuigui.png')
plt.show()
|
-
|