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)
"""
#-*--------------導(dǎo)入包----------------*-#
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)
#-*--------------截取要用的數(shù)據(jù)----------------*-#
level_need = 5
"""
level_need與等壓面的對應(yīng)表
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]
#-*----------------------------畫底圖---------------------------------*-#
#區(qū)域設(shè)置
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)
#--------------------------畫經(jīng)線緯線-----------------------#
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])
#圖標(biāo)題
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