| 
 
	积分5981贡献 精华在线时间 小时注册时间2022-2-27最后登录1970-1-1 
 | 
 
| 
本帖最后由 wuliqin 于 2022-5-5 13:53 编辑
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  
 请教各位会使用python处理数据和画图的前辈、同伴们,当数据的结构是以下的类型,导致画出来的图经纬度错位了(经度错位90°,纬度从0开始),应该使用什么方法调整呢?我网上一直找不到解决方法,不知道有没有小伙伴遇到过跟我一样的问题然后有方法解决的,感谢指点!!
 
 import netCDF4 as nc
 import numpy as np
 import matplotlib.pyplot as plt
 from mpl_toolkits.basemap import Basemap
 import xarray as xr
 from matplotlib.colors import ListedColormap
 
 file = 'F:/thetao_Omon_ACCESS-CM2_historical_r1i1p1f1_gn_201001-201412.nc'
 a1 = xr.open_dataset(file)
 print(a1)   # thetao  (time, lev, j, i) float32 ...
 
 lat = (a1['j'][:])
 lon = (a1['i'][:])
 time = (a1['time'][:])
 lev = (a1['lev'][:])
 thetao = a1['thetao'][:][:, :, :, :]
 print(thetao)
 print(thetao.shape)   # (60, 50, 300, 360)
 
 map = Basemap(lat_0=0, lon_0=0, llcrnrlat=-90., llcrnrlon=0., urcrnrlat=90., urcrnrlon=360., resolution='l')
 lon, lat = np.meshgrid(lon, lat)    # np.meshgrid生成网格点坐标矩阵
 x, y = map(lon, lat)                  # 将网格点坐标对应转换成地理经纬度
 
 cmap = plt.cm.ocean_r        # 和以下这3行是截取想要的cmap
 newcolors =cmap(np.linspace(0, 1, 256))
 newcmap = ListedColormap(newcolors[10:190])
 
 map.drawmeridians(np.arange(0, 360.001, 20), labels=[1, 0, 0, 1], linewidth=0)
 map.drawparallels(np.arange(-90, 90.001, 10), labels=[1, 0, 0, 1], linewidth=0)
 
 map.drawcoastlines(linewidth=0.2, color='black')           # 绘制海岸线
 map.contourf(x, y, thetao[2, 5, :, :], levels=np.arange(0, 30, 2), cmap=newcmap, alpha=1.0, extend='both')    # 填色绘图
 cbar = map.colorbar(location='bottom', pad="10%",)                   # 添加色标
 cbar.set_label('℃')  # 添加色标标签
 
 plt.show()
 使用map.contourf(lon, lat, thetao[2, 5, :, :], levels=np.arange(-5, 35, 2), cmap=newcmap, extend='both', latlon=True)可以纠正经纬度的错位,但是出的图有问题
 
 
 | 
 |