Python气象图形的绘制——Day1

需要用到的库

import xarray as xr                #数据读取
import numpy as np                 #用于计算
import matplotlib.pyplot as plt    #数据可视化
import cartopy.crs as ccrs         #地图投影
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter

nc数据的读取

file_name = 'd:/hgt.mon.mean.nc'
file = xr.open_dataset(file_name)
#print(file)
var=file["hgt"]
var_=var.loc['1980-01':'2010-12']
hgt=var_[6::12,2,:,:]

取平均

mean=np.nanmean(hgt,axis=0)

数组的加减

例如:纬偏图中,先要将lon_mean转为竖着的,然后用二维的数组减去一维的

lon_ano=var_1[0,2,:,:]-lon_mean.reshape(-1,1)

画图

fig=plt.figure(dpi=600)
#ax1 = fig.add_subplot(111)
ax1 = plt.subplot(111, projection=ccrs.PlateCarree(central_longitude=180))
#ax1.set_global() #使得轴域(Axes即两条坐标轴围城的区域)适应地图的大小
ax1.coastlines() #画出海岸线
#坐标轴
ax1.set_xticks([0, 60, 120, 180, 240, 300, 360], crs=ccrs.PlateCarree())
ax1.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree())
lon_formatter = LongitudeFormatter()
lat_formatter = LatitudeFormatter()
#加°E等
ax1.xaxis.set_major_formatter(lon_formatter)
ax1.yaxis.set_major_formatter(lat_formatter)

#cmap   = plt.get_cmap('bwr')  #选择色标
plt.contourf(lon,lat,ano,cmap='Spectral_r',linewidth=.5,transform=ccrs.PlateCarree())
plt.colorbar(shrink=1,orientation = 'horizontal')#(使色条横向)
ax1.set_title('850hPa hgt 2015_07 ano',)
cs = plt.contour(lon,lat,ano,colors='k',transform=ccrs.PlateCarree()) #绘制填色图。颜色设置为黑色
plt.clabel(cs,fmt = '%1.0f',fontsize = 7)  #添加等值线标签,不保留小数
plt.savefig('d:/Jul_850_ano.png') #保存图片
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值