天气学原理插图复现(四)——平均温度场经向剖面图

使用数据:slp.mon.ltm.1991-2020.nc

使用库:Matplotlib、NumPy、netCDF4、Cartopy

彩色图像 

import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.mpl.ticker as cmt
import cartopy.crs as ccrs
import matplotlib.path as mpath
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter)
import matplotlib as mpl
import matplotlib.ticker as mticker

plt.rcParams['font.sans-serif']= ['Microsoft YaHei'] # 设置“微软雅黑”,图上显示出中文
plt.rcParams['axes.unicode_minus'] = False # 设置中文后,解决坐标轴上负号显示问题

para_level = 1000
f = nc.Dataset(r"slp.mon.ltm.1991-2020.nc",'r')
lat = f.variables['lat'][:]
lon0 = f.variables['lon'][:]
time = nc.num2date(f.variables['time'][:],f.variables['time'].units).data
months = np.array([i.month for i in time])

def pa(para_month):
    slp = f.variables['slp'][:]
    index_month = np.where(months==para_month)[0][0]
    slp = slp[index_month]
    slp, lon = add_cyclic_point(slp, coord=lon0)
    Lon, Lat = np.meshgrid(lon,lat)
    return Lon,Lat,slp

Lon1,Lat1,slp1=pa(1)
Lon2,Lat2,slp2=pa(7)
fig = plt.figure(figsize=(11,14))

#001
ax = plt.subplot(211,projection=ccrs.PlateCarree(central_longitude=180))
ax.set_extent([-180,180,-90,90])
levels = np.arange(970,1060,5)
ec = ax.contourf(Lon1-180,Lat1, slp1,cmap = 'RdBu_r',levels=levels)
ac = ax.contour(Lon1-180,Lat1, slp1,levels=levels,colors='black',linewidths=1,linestyles='-')
fig.colorbar(ec)
ax.clabel(ac)
ax.set_xticks([-180,-150,-120,-90,-60,-30,0,30,60,90,120,150,180])
ax.set_yticks([-90,-60,-30,0,30,60,90])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter()) 
ax.add_feature(cfeature.COASTLINE)
ax.tick_params(axis='both',which='major',labelsize=10,direction='out',length=5,width=0.8)
ax.minorticks_on()
ax.tick_params(axis='both',which='minor',direction='out',width=0.8,top=True,right=True)
plt.title("1月")

#002
ax = plt.subplot(212,projection=ccrs.PlateCarree(central_longitude=180))
ax.set_extent([-180,180,-90,90])
levels = np.arange(970,1060,5)
ec = ax.contourf(Lon2-180,Lat2, slp2,cmap = 'RdBu_r',levels=levels)
ac = ax.contour(Lon2-180,Lat2, slp2,levels=levels,colors='black',linewidths=1,linestyles='-')
fig.colorbar(ec)
ax.clabel(ac)
ax.set_xticks([-180,-150,-120,-90,-60,-30,0,30,60,90,120,150,180])
ax.set_yticks([-90,-60,-30,0,30,60,90])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter()) 
ax.add_feature(cfeature.COASTLINE)
ax.tick_params(axis='both',which='major',labelsize=10,direction='out',length=5,width=0.8)
ax.minorticks_on()
ax.tick_params(axis='both',which='minor',direction='out',width=0.8,top=True,right=True)
plt.title("7月")

plt.suptitle("图4-1-5   平均海平面气压场(单位:hPa)",fontsize='xx-large')

plt.savefig("图4-1-5.png",dpi=800)
plt.show()

 黑白图像

import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.mpl.ticker as cmt
import cartopy.crs as ccrs
import matplotlib.path as mpath
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter)
import matplotlib as mpl
import matplotlib.ticker as mticker

plt.rcParams['font.sans-serif']= ['Microsoft YaHei'] # 设置“微软雅黑”,图上显示出中文
plt.rcParams['axes.unicode_minus'] = False # 设置中文后,解决坐标轴上负号显示问题

para_level = 1000
f = nc.Dataset(r"slp.mon.ltm.1991-2020.nc",'r')
lat = f.variables['lat'][:]
lon0 = f.variables['lon'][:]
time = nc.num2date(f.variables['time'][:],f.variables['time'].units).data
months = np.array([i.month for i in time])


def pa(para_month):
    slp = f.variables['slp'][:]
    index_month = np.where(months==para_month)[0][0]
    slp = slp[index_month]
    slp, lon = add_cyclic_point(slp, coord=lon0)
    Lon, Lat = np.meshgrid(lon,lat)
    return Lon,Lat,slp

Lon1,Lat1,slp1=pa(1)
Lon2,Lat2,slp2=pa(7)
fig = plt.figure(figsize=(11,14))

#001
ax = plt.subplot(211,projection=ccrs.PlateCarree(central_longitude=180))
ax.set_extent([-180,180,-90,90])
levels = np.arange(970,1060,5)
ac = ax.contour(Lon1-180,Lat1, slp1,levels=levels,colors='black',linewidths=1,linestyles='-')
ax.clabel(ac)
ax.set_xticks([-180,-150,-120,-90,-60,-30,0,30,60,90,120,150,180])
ax.set_yticks([-90,-60,-30,0,30,60,90])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter()) 
ax.add_feature(cfeature.COASTLINE)
ax.tick_params(axis='both',which='major',labelsize=10,direction='out',length=5,width=0.8)
ax.minorticks_on()
ax.tick_params(axis='both',which='minor',direction='out',width=0.8,top=True,right=True)
plt.title("1月")

#002
ax = plt.subplot(212,projection=ccrs.PlateCarree(central_longitude=180))
ax.set_extent([-180,180,-90,90])
levels = np.arange(970,1060,5)
ac = ax.contour(Lon2-180,Lat2, slp2,levels=levels,colors='black',linewidths=1,linestyles='-')
ax.clabel(ac)
ax.set_xticks([-180,-150,-120,-90,-60,-30,0,30,60,90,120,150,180])
ax.set_yticks([-90,-60,-30,0,30,60,90])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter()) 
ax.add_feature(cfeature.COASTLINE)
ax.tick_params(axis='both',which='major',labelsize=10,direction='out',length=5,width=0.8)
ax.minorticks_on()
ax.tick_params(axis='both',which='minor',direction='out',width=0.8,top=True,right=True)
plt.title("7月")

plt.suptitle("图4-1-5   平均海平面气压场(单位:hPa)",fontsize='xx-large')

plt.savefig("图4-1-5(黑白).png",dpi=800)
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值