- 积分
- 8192
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2020-12-28
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2022-4-12 10:01:18
|
显示全部楼层
- from wrf import getvar,get_cartopy
- import xarray as xr
- import numpy as np
- import matplotlib.pyplot as plt
- import cartopy.crs as ccrs
- import cartopy.feature as cfeature
- from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
- from netCDF4 import Dataset as nc
- import cmaps
- ncfile=nc(r'D:/wrf/wrfout_d01_2004-06-25_04_00_00.nc')
- slp=getvar(ncfile, "slp")
- rain_exp=np.array(getvar(ncfile, "RAINNC"))
- rain_con=np.array(getvar(ncfile, "RAINC"))
- rain_tot=np.array(rain_exp+rain_con)
- rain1=getvar(ncfile, "RAINNC")
- rain2=getvar(ncfile, "RAINC")
- lon=getvar(ncfile, "XLONG")
- lat=getvar(ncfile, "XLAT")
- rain=(rain1+rain2)
- fig = plt.figure(figsize=(10, 14),dpi=100)
- box=[0,180,-30,30.5]
- scale='50m'
- xstep, ystep = 40, 15
- #######plot####################
- def make_map(ax, title):
- # set_extent set crs
- ax.set_extent(box, crs=ccrs.PlateCarree())
- land = cfeature.NaturalEarthFeature('physical',
- 'land',
- scale,
- edgecolor='grey',
- facecolor='none',zorder=1
- )
- ax.add_feature(land) # set land color
- ax.coastlines(scale) # set coastline resolution
- # set coordinate axis
- ax.set_xticks(np.arange(box[0],box[1], xstep),crs=ccrs.PlateCarree())
- ax.set_yticks(np.arange(box[2], box[3]+ystep, ystep),crs=ccrs.PlateCarree(central_longitude=0))
- ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label =False))#经度0不加标识
- ax.yaxis.set_major_formatter(LatitudeFormatter())
- ax.set_title(title, fontsize=15, loc='left',pad=10)
- ax.tick_params(which='major',
- direction='out',
- length=8,
- width=0.99,
- pad=3,
- labelsize=15,
- bottom=True, left=True, right=False, top=False)
- return ax
- ax0=fig.add_subplot(311,projection=ccrs.PlateCarree())
- ax0=make_map(ax0,'2004-06-25_04--RAINC(set levels(0,5.1,0.1))')
- cb0=ax0.contourf(lon,lat,rain2,transform=ccrs.PlateCarree(),levels=np.arange(0,5.1,0.1))
- c0=fig.colorbar(cb0,ax=ax0,shrink=0.8,pad=0.05,aspect=13)
- ax1=fig.add_subplot(312,projection=ccrs.PlateCarree())
- ax1=make_map(ax1,'2004-06-25_04--RAINNC(set levels(0,5.1,0.1))')
- cb1=ax1.contourf(lon,lat,rain1,transform=ccrs.PlateCarree(),levels=np.arange(0,5.1,0.1))
- c1=fig.colorbar(cb1,ax=ax1,shrink=0.8,pad=0.05,aspect=13)
- ax2=fig.add_subplot(313,projection=ccrs.PlateCarree())
- ax2=make_map(ax2,'2004-06-25_04--RAINNC+RAINC(set levels(0,5.1,0.5))')
- cb2=ax2.contourf(lon,lat,rain,transform=ccrs.PlateCarree(),levels=np.arange(0,5.1,0.5))
- c2=fig.colorbar(cb2,ax=ax2,shrink=0.8,pad=0.05,aspect=13)
- plt.show()
复制代码 |
|