- 积分
- 277
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-1-7
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 王先生 于 2019-3-29 23:27 编辑
继续来问一波干货。先上代码
#—*— coding utf-8 -*-
'''
Created on Wed 27 10:22:00 2019
@auther WYL
'''
import numpy as np
import matplotlib.pyplot as plt
import netCDF4 as nc
obj = nc.Dataset('f:/merra2/W/MERRA2_400.inst3_3d_asm_Np.20120601.SUB.nc4')
lat = obj.variables['lat'][:]
lev = obj.variables['lev'][0:20]
lon = obj.variables['lon'][220:280]
time= obj.variables['time'][0]
W = obj.variables['OMEGA'][0,0:20,100,220:280]
#print('W的单位',obj.variables['OMEGA'])
#print(lev[26])
obj2 = nc.Dataset("f:/merra2/QV/MERRA2_400.inst3_3d_asm_Np.20120610.SUB.nc4")
#print(obj)
time_bnds = obj2.variables['time_bnds'][:]
#print(time_bnds[:])
time1 = obj2.variables['time'][0]
lev1 = obj2.variables['lev'][0:20]
lat1 = obj2.variables['lat'][:]
lon1 = obj2.variables['lon'][220:280]
QV = obj2.variables['QV'][0,0:20,100,220:280]
QV = QV*1000
QV1=np.ma.array(QV1, mask=QV1>0)
#print(lat[100])
plt.figure(figsize=(12,6))
plt.semilogy()#取对数坐标
plt.gca().invert_yaxis()#Y轴坐标反转
lons,levs=np.meshgrid(lon,lev)
x,y = lons,levs #W=np.arange(-0.3,0,0.05)
Welem = obj.variables['OMEGA'][0,0:20,100,220:280]
shade = plt.contour(x,y,Welem,5,colors='k')
shade1= plt.contourf(x,y,QV1,10,cmap='jet')
plt.colorbar(shade1)
plt.clabel(shade,inline=1,fontsize=10)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.title('35°N垂直速度、水汽叠加图(垂直速度:Pa·s﹣,水汽:g·kg﹣1)')
plt.show()
感谢2楼提供的语句。@ 。解决方案如下,选择文件中固定值域进行画图,把大于0的数据都mask掉就好了
Welem = np.ma.array(Welem, mask=Welem>0)
或者,你可以可以指定标contour的层面
shade = plt.contour(x,y,Welem,levels=[0, -1, -2, -3, ...],colors='k')
|
-
|