大气科学、气候变化

python画月平均气温分布(2018.10,500hPa)

2018-11-17  本文已影响119人  王琛NUIST

1 资料来源

NCEP/NCAR Reanalysis 1

2 所用到的包

netCDF

numpy

matplotlib.pyplot

Basemap

3 代码

"""
-*- coding: utf-8 -*-
  Author   : WANG Chen,Nanjing University of Information 
             Science & Technology
  Email    : nuistwangchen@163.com
  Date     : 2018-11-17
  Version  : 1.0
  Describe : Draw Chinese average temperature distribution 
             in October 2018(500hPa)
"""

#-*--------------导入包----------------*-#
import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

#-*--------------读NC文件----------------*-#
nc_obj = nc.Dataset('air.mon.mean.nc')
print(nc_obj.variables.keys())#打印变量信息
lon = nc_obj.variables['lon']
lon = np.array(lon)
lat = nc_obj.variables['lat']
lat = np.array(lat)
temperature = nc_obj.variables['air']
temperature = np.array(temperature)
level = nc_obj.variables['level']
level = np.array(level)

#-*--------------截取要用的数据----------------*-#
level_need = 5
"""
level_need与等压面的对应表

level_need :   0    1    2    3    4
pressure   : 1000  925  850  700  600 
level_need :   5    6    7    8    9
pressure   :  500  400  300  250  200  
level_need :   10   11   12   13   14
pressure   :  150  100   70   50   30
level_need :   15   16
pressure   :   20   10
"""
temperature_need = temperature[849,level_need,14:35,18:56]

#-*----------------------------画底图---------------------------------*-#
#区域设置
map = Basemap(llcrnrlon=70, llcrnrlat=5, urcrnrlon=137, urcrnrlat=55)
#画省界
map.readshapefile(r'G:\python_material\MapOfChina\gadm36_CHN_shp\gadm36_CHN_1',
                'states', drawbounds = True)
#画台湾省
ax=plt.gca()
map.readshapefile(r'G:\python_material\MapOfChina\gadm36_TWN_shp\gadm36_TWN_1',
                'taiwan', drawbounds=True)
#画海岸线和国界
map.drawcoastlines()
map.drawcountries(linewidth=1.5)

#-*----------------------------画等温线---------------------------------*-#
Lon,Lat = np.meshgrid(lon[18:56],lat[14:35])
X,Y = map(Lon,Lat)
c = map.contourf(X,Y,temperature_need,30,cmap=plt.cm.RdBu_r)
map.colorbar(c)

#--------------------------画经线纬线-----------------------#
parallels = np.linspace(3,55,5)
map.drawparallels(parallels,labels=[True,False,False,False])
meridians = np.linspace(70,140,5)
map.drawmeridians(meridians,labels=[False,False,False,True])

#图标题
plt.title(r'$Chinese\ average\ temperature\ distribution\ in\ October\ 2018\ (500hPa)$',fontsize=22)

plt.show()

4 月平均气温分布图

China's average temperature distribution in October 2018.png
上一篇下一篇

猜你喜欢

热点阅读