python 利用cartopy绘制世界地图中部分地区的风场的流线形式
先看效果图图(1982-1984 6.7.8月200hPa高度风场,60°E-150°E,0-40°N)
所用的画流线的函数
plt.streamplot(X, Y, u, v, density=10, linewidth=0.4, arrowsize=0.5)
其中density代表流线的密度,linewidth代表线的宽度,arrowsize代表箭头的大小
streamplot具体解释 官方文档
其余代码解释参考这篇博客 python 利用cartopy绘制世界地图中部分地区的风场
全部代码
import cartopy.crs as ccrs
import cartopy.feature as cf
import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt
# 设置画图字体的大小
plt.rcParams.update({'font.size': 4})
# 解决中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
# 解决负号乱码问题
plt.rcParams['axes.unicode_minus'] = False
fig = plt.figure(figsize=(2, 2), dpi=400)
ax = fig.add_axes([0.2, 0, 0.6, 1], projection=ccrs.PlateCarree(central_longitude=0))
ax.add_feature(cf.LAND.with_scale('110m'))
ax.add_feature(cf.OCEAN.with_scale('110m'))
ax.add_feature(cf.COASTLINE.with_scale('110m'), lw=0.4)
ax.add_feature(cf.RIVERS.with_scale('110m'), lw=0.4)
gl = ax.gridlines(draw_labels=True, linestyle=":", linewidth=0.3, color='k')
ax.set_title('gridlines经纬度风格', fontsize=2)
file = 'DATA.nc'
nc_object = nc.Dataset(file)
lons = nc_object.variables['lon'][:]
lats = nc_object.variables['lat'][:]
h = nc_object.variables['H'][:]
# print(lons)
# print(lats)
U = nc_object.variables['U']
V = nc_object.variables['V']
u = []
v = []
for j in [5, 6, 7]:
for i in [j + i * 12 for i in range(4)]:
u.append(U[i, 0, :, :])
v.append(V[i, 0, :, :])
u = np.mean(u, axis=0)
v = np.mean(v, axis=0)
X, Y = np.meshgrid(lons, lats)
q = plt.streamplot(X, Y, u, v, density=10, linewidth=0.4, arrowsize=0.5)
plt.title('1982-1985 JJA wind 200hPa')
plt.xlabel('lon')
plt.ylabel('lat')
plt.show()