title: Python绘制气象风场
date: 2021-08-05 21:01:52
tag:

气象风场数据来源为欧洲中心再分析数据ERA5 hourly data on pressure levels from 1979 to present (copernicus.eu)

#在地图上绘制风场和轨迹
import matplotlib.pyplot as plt###引入库包
import numpy as np
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.ticker as mticker
import netCDF4 as nc
import matplotlib.pyplot as pltmpl.rcParams["font.family"] = 'Arial'  #默认字体类型
mpl.rcParams["mathtext.fontset"] = 'cm' #数学文字字体
mpl.rcParams["font.size"] = 15   #字体大小
mpl.rcParams["axes.linewidth"] = 1   #轴线边框粗细(默认的太粗了)f1=nc.Dataset('wind.nc') #打开.nc文件
#读取文件中的数据
lat=f1.variables['latitude'][:]
lon=f1.variables['longitude'][:]
time=f1.variables['time'][:]
u1000=f1.variables['u'][:]#下载的1000hPa的风场数据
v1000=f1.variables['v'][:]lon2d, lat2d = np.meshgrid(lon, lat)
u1000_aim=np.mean(u1000[4:6,:,:],axis=0)
v1000_aim=np.mean(v1000[4:6,:,:],axis=0)proj = ccrs.PlateCarree(central_longitude=180)
fig = plt.figure(figsize=(10,8),dpi=550)  # 创建画布
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图u_all=u1000_aim
v_all=v1000_aim#-----------绘制地图-------------------------------------------# ax.add_feature(cfeature.LAND.with_scale('50m'))####添加陆地######
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))#####添加海岸线#########
# ax.add_feature(cfeature.OCEAN.with_scale('50m'))######添加海洋#########-----------添加经纬度---------------------------------------
extent=[100,269,-80,80]##经纬度范围
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0., color='k', alpha=0.5, linestyle='--')
dlon, dlat = 45, 30   #设置步长
xticks = np.arange(0, 360.1, dlon)  #设置绘图范围
yticks = np.arange(-90, 90.1, dlat)
ax.set_xticks(xticks, crs=ccrs.PlateCarree())  #图幅设置坐标轴刻度
ax.set_yticks(yticks, crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))  #设置坐标轴刻度标签格式
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.set_extent(extent)     #显示所选择的区域#----------修改国界,并添加省界-----------------------------
#在这个网站上可以找到dat文件,https://gmt-china.org/data/
# with open('C:/Users/hj/.local/share/cartopy/shapefiles/natural_earth/physical/CN-border-La.dat') as src:
#     context = src.read()
#     blocks = [cnt for cnt in context.split('>') if len(cnt) > 0]
#     borders = [np.fromstring(block, dtype=float, sep=' ') for block in blocks]
# for line in borders:
#     ax.plot(line[0::2], line[1::2], '-', color='k',lw=0.3, transform=ccrs.Geodetic())#-------------------plot---------------------------
#levels = np.arange(1004, 1032 + 1, 1)
#cb = ax.contourf(lon2d,lat2d,msl_all, levels=levels, cmap='Spectral_r',transform=ccrs.PlateCarree())cq =ax.quiver(lon2d[::20,::20],lat2d[::20,::20],u_all[::20,::20],v_all[::20,::20],color='k',scale=250,zorder=10,width=0.002,headwidth=3,headlength=4.5,transform=ccrs.PlateCarree())   plt.savefig('pic.jpg',dpi=300)

画出的图如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gU4EB1Zt-1629730874406)(https://z3.ax1x.com/2021/08/05/feDIN8.jpg)]

下面画风速的颜色图:

#在地图上绘制风场和轨迹
import matplotlib.pyplot as plt###引入库包
import numpy as np
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.ticker as mticker
import netCDF4 as nc
import matplotlib.pyplot as pltmpl.rcParams["font.family"] = 'Arial'  #默认字体类型
mpl.rcParams["mathtext.fontset"] = 'cm' #数学文字字体
mpl.rcParams["font.size"] = 15   #字体大小
mpl.rcParams["axes.linewidth"] = 1   #轴线边框粗细(默认的太粗了)f1=nc.Dataset('wind.nc') #打开.nc文件
#读取文件中的数据
lat=f1.variables['latitude'][:]
lon=f1.variables['longitude'][:]
time=f1.variables['time'][:]
u1000=f1.variables['u'][:]#下载的1000hPa的风场数据
v1000=f1.variables['v'][:]lon2d, lat2d = np.meshgrid(lon, lat)
u1000_aim=np.mean(u1000[4:6,:,:],axis=0)
v1000_aim=np.mean(v1000[4:6,:,:],axis=0)proj = ccrs.PlateCarree(central_longitude=180)
fig = plt.figure(figsize=(10,8),dpi=550)  # 创建画布
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图u_all=u1000_aim
v_all=v1000_aim
ws=np.sqrt(u_all*u_all+v_all*v_all)#-----------绘制地图-------------------------------------------# ax.add_feature(cfeature.LAND.with_scale('50m'))####添加陆地######
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))#####添加海岸线#########
# ax.add_feature(cfeature.OCEAN.with_scale('50m'))######添加海洋#########-----------添加经纬度---------------------------------------
extent=[100,269,-80,80]##经纬度范围
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0., color='k', alpha=0.5, linestyle='--')
dlon, dlat = 45, 30   #设置步长
xticks = np.arange(0, 360.1, dlon)  #设置绘图范围
yticks = np.arange(-90, 90.1, dlat)
ax.set_xticks(xticks, crs=ccrs.PlateCarree())  #图幅设置坐标轴刻度
ax.set_yticks(yticks, crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))  #设置坐标轴刻度标签格式
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.set_extent(extent)     #显示所选择的区域#cb = ax.contourf(lon2d,lat2d,ws, levels=levels, cmap='Spectral_r',transform=ccrs.PlateCarree())
cb = ax.pcolormesh(lon2d,lat2d,ws, cmap='Spectral_r',transform=ccrs.PlateCarree())
cbar=fig.colorbar(cb,ax=(ax),orientation='vertical',ticks=np.arange(0, 24 + 4,4),aspect=20,shrink=0.9,pad=0.02)
#pad调和图的距离
#aspect调颜色棒的宽度
#shrink调颜色棒的长度
cbar.ax.tick_params(pad=0.02,length=2,width=0.5)plt.savefig('pic3.jpg',dpi=300)

画出的图如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TlKE7PMK-1629730874411)(https://z3.ax1x.com/2021/08/05/ferTVx.jpg)]

画航线轨迹和异常点

#在地图上绘制风场和轨迹
import matplotlib.pyplot as plt###引入库包
import numpy as np
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.ticker as mticker
import netCDF4 as nc
import matplotlib.pyplot as pltmpl.rcParams["font.family"] = 'Arial'  #默认字体类型
mpl.rcParams["mathtext.fontset"] = 'cm' #数学文字字体
mpl.rcParams["font.size"] = 15   #字体大小
mpl.rcParams["axes.linewidth"] = 1   #轴线边框粗细(默认的太粗了)import pandas as pd
traj=pd.read_csv('Antarctic28.csv')
traj_lon=traj.iloc[:,3]
traj_lat=traj.iloc[:,2]aim_lat=[0.752, -12.006, -62.226, -62.233, -64.400, -69.332]
aim_lon=[119.1357833,115.1921333,-58.92556667,-58.91463333,-16.3727,76.43843333]proj = ccrs.PlateCarree(central_longitude=45)  #中国为左
fig = plt.figure(figsize=(10,8),dpi=550)  # 创建画布
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图#-----------绘制地图-------------------------------------------# ax.add_feature(cfeature.LAND.with_scale('50m'))####添加陆地######
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))#####添加海岸线#########
# ax.add_feature(cfeature.OCEAN.with_scale('50m'))######添加海洋#########-----------添加经纬度---------------------------------------
extent=[-90,135,-80,80]##经纬度范围
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0., color='k', alpha=0.5, linestyle='--')
dlon, dlat = 45, 30   #设置步长
xticks = np.arange(0, 360.1, dlon)  #设置绘图范围
yticks = np.arange(-90, 90.1, dlat)
ax.set_xticks(xticks, crs=ccrs.PlateCarree())  #图幅设置坐标轴刻度
ax.set_yticks(yticks, crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))  #设置坐标轴刻度标签格式
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.set_extent(extent)     #显示所选择的区域#cb = ax.contourf(lon2d,lat2d,ws, levels=levels, cmap='Spectral_r',transform=ccrs.PlateCarree())
# cb = ax.pcolormesh(lon2d,lat2d,ws, cmap='Spectral_r',transform=ccrs.PlateCarree(),alpha=0.8)
# cbar=fig.colorbar(cb,ax=(ax),orientation='vertical',ticks=np.arange(0, 24 + 4,4),
#                   aspect=10,shrink=0.5,pad=0.02)
# #pad调和图的距离
# #aspect调颜色棒的宽度
# #shrink调颜色棒的长度
# cbar.ax.tick_params(pad=0.02,length=2,width=0.5)
ax.plot(traj_lon[0:3525],traj_lat[0:3525],transform=ccrs.PlateCarree(),color='red')
ax.plot(traj_lon[3525:],traj_lat[3525:],transform=ccrs.PlateCarree(),color='b')ax.scatter(aim_lon[0:4],aim_lat[0:4],transform=ccrs.PlateCarree(),s=300,color='gray',alpha=0.6)
ax.scatter(aim_lon[4:],aim_lat[4:],transform=ccrs.PlateCarree(),s=300,color='gray',alpha=0.6)ax.scatter(aim_lon[0:4],aim_lat[0:4],transform=ccrs.PlateCarree(),s=50,color='red')
ax.scatter(aim_lon[4:],aim_lat[4:],transform=ccrs.PlateCarree(),s=50,color='b')
plt.savefig('pic4.jpg',dpi=300)

画出的图如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d4jLH1Dz-1629730874414)(https://z3.ax1x.com/2021/08/05/fes6OA.jpg)]

画出异常点附近的风场

#在地图上绘制风场和轨迹
import matplotlib.pyplot as plt###引入库包
import numpy as np
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.ticker as mticker
import netCDF4 as nc
import matplotlib.pyplot as pltmpl.rcParams["font.family"] = 'Arial'  #默认字体类型
mpl.rcParams["mathtext.fontset"] = 'cm' #数学文字字体
mpl.rcParams["font.size"] = 15   #字体大小
mpl.rcParams["axes.linewidth"] = 1   #轴线边框粗细(默认的太粗了)f1=nc.Dataset('wind.nc') #打开.nc文件
#读取文件中的数据
lat=f1.variables['latitude'][:]
lon=f1.variables['longitude'][:]
time=f1.variables['time'][:]
u1000=f1.variables['u'][:]#下载的1000hPa的风场数据
v1000=f1.variables['v'][:]lon2d, lat2d = np.meshgrid(lon, lat)
u1000_aim=np.mean(u1000[4:6,:,:],axis=0)
v1000_aim=np.mean(v1000[4:6,:,:],axis=0)import pandas as pd
traj=pd.read_csv('Antarctic28.csv')
traj_lon=traj.iloc[:,3]
traj_lat=traj.iloc[:,2]aim_lat=[0.752, -12.006, -62.226, -62.233, -64.400, -69.332]
aim_lon=[119.1357833,115.1921333,-58.92556667,-58.91463333,-16.3727,76.43843333]mpl.rcParams["font.size"] = 18   #字体大小
proj = ccrs.PlateCarree(central_longitude=115)  #中国为左
fig = plt.figure(figsize=(10,8),dpi=550)  # 创建画布
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图u_all=u1000_aim
v_all=v1000_aim
ws=np.sqrt(u_all*u_all+v_all*v_all)#-----------绘制地图-------------------------------------------# ax.add_feature(cfeature.LAND.with_scale('50m'))####添加陆地######
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))#####添加海岸线#########
# ax.add_feature(cfeature.OCEAN.with_scale('50m'))######添加海洋#########-----------添加经纬度---------------------------------------
extent=[118,120.5,-0.5,2]##经纬度范围
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0., color='k', alpha=0.5, linestyle='--')
dlon, dlat = 1, 0.5   #设置步长
xticks = np.arange(117, 121.1, dlon)  #设置绘图范围
yticks = np.arange(-1, 2.1, dlat)
ax.set_xticks(xticks, crs=ccrs.PlateCarree())  #图幅设置坐标轴刻度
ax.set_yticks(yticks, crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=True))  #设置坐标轴刻度标签格式
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.set_extent(extent)     #显示所选择的区域# levels = np.arange(0, 4 + 1, 1)
#cb = ax.contourf(lon2d,lat2d,ws, levels=levels, cmap='Spectral_r',transform=ccrs.PlateCarree())
cb = ax.pcolormesh(lon2d,lat2d,ws, cmap='Spectral_r',transform=ccrs.PlateCarree(),alpha=0.8,vmin=0.0,vmax=4)
cbar=fig.colorbar(cb,ax=(ax),orientation='vertical',ticks=np.arange(0, 4 + 1,1),aspect=10,shrink=0.5,pad=0.02)
#pad调和图的距离
#aspect调颜色棒的宽度
#shrink调颜色棒的长度
cbar.ax.tick_params(pad=0.02,length=2,width=0.5)ax.plot(traj_lon[0:3525],traj_lat[0:3525],transform=ccrs.PlateCarree(),color='red')
ax.plot(traj_lon[3525:],traj_lat[3525:],transform=ccrs.PlateCarree(),color='b')ax.scatter(aim_lon[0:4],aim_lat[0:4],transform=ccrs.PlateCarree(),s=300,color='black',alpha=0.6)
ax.scatter(aim_lon[4:],aim_lat[4:],transform=ccrs.PlateCarree(),s=300,color='black',alpha=0.6)ax.scatter(aim_lon[0:4],aim_lat[0:4],transform=ccrs.PlateCarree(),s=50,color='red')
ax.scatter(aim_lon[4:],aim_lat[4:],transform=ccrs.PlateCarree(),s=50,color='b')cq = ax.quiver(lon2d[::1,::1],lat2d[::1,::1],u_all[::1,::1],v_all[::1,::1],color='k',scale=20,zorder=10,width=0.002,headwidth=3,headlength=4.5,transform=ccrs.PlateCarree())plt.savefig('pic5.jpg',dpi=300)

画出的图如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pQQVy9nE-1629730874416)(https://z3.ax1x.com/2021/08/05/feyp6J.jpg)]

Python绘制气象风场相关推荐

  1. python绘制北极风场与位势高度场/python cartopy极地投影重叠问题解决

    背景 python作为胶水语言,近年来在气象数据处理与可视化中有着极为广泛地应用,诸多第三方库极为便利地满足了气象研究者处理数据与绘图的要求,处理数据的包:xarray.pandas,读取不同气象格式 ...

  2. Python绘制气象实用地图(附代码和测试数据) !

    前面的推文对于常用的Python绘图工具都有了一些介绍,在这里就不赘述了.本文主要就以下几个方面:"中国区域绘图"."包含南海"."兰伯特投影带经纬度 ...

  3. python绘制气象等值线图_用Matplotlib绘制Python等值线图

    我试图用Python的Matplotlib包绘制等高线图.我试图得到与在this其他堆栈溢出帖子中看到的结果相似的结果.但是,我遇到了一个问题,它说有一个类型错误,它告诉我TypeError: Inv ...

  4. python绘制气象等值线图_气象要素场等值线图自动绘制

    气象要素场等值线图自动绘制 汤子东 ; 冯晓云 ; 郑明玺 ; 朱君松 ; 奚秀芬 [期刊名称] <气象科技> [年 ( 卷 ), 期] 2006(034)004 [摘要] 根据业务的特殊 ...

  5. python绘制气象海洋不规则空间站点数据的填色图

    大气海洋领域有很多空间分布的二维数据需要绘制成填色图(或等值线图),python中常用matplotlib中的contour或contourf函数,但是这两个函数要求数据分布于规则网格上. 对于很多模 ...

  6. python绘制气象等值线图_利用Python插值绘制等值线图

    最近需要根据有限的站位点绘制插值等值线图,在网上中文搜索一通,只发现了这货Matplot Basemap 画湖北地图.插值.等值线,要么就是对这货的转载,这货不提供数据的形式,但是基本的代码思路还是不 ...

  7. Meteorographica:一个用Python绘制天气图的气象代码库

    大家好,Meteorographica是一个由个人维护的,仅用于绘制特定天气图的气象代码库,他的官网是>> Meteorographica: python code for plottin ...

  8. python绘制折线图先对数据进行处理_python气象数据分析并绘制折线图-女性时尚流行美容健康娱乐mv-ida网...

    女性时尚流行美容健康娱乐mv-ida网 mvida时尚娱乐网 首页 美容 护肤 化妆技巧 发型 服饰 健康 情感 美体 美食 娱乐 明星八卦 首页 > 高级搜索 excel 2010巧妙处理 折 ...

  9. python气象处理第三弹-绘制气象站点分布

    python气象处理第三弹-绘制气象站点分布 python气象处理第三弹-绘制气象站点分布 python气象处理第三弹-绘制气象站点分布 前言 一.下载并转换中国气象站点数据? 二.使用步骤 1.引入 ...

最新文章

  1. 2021年大数据Flink(四十六):扩展阅读 异步IO
  2. Shell基础-环境变量配置文件
  3. gettext()方法输出空白_如何将文档内容输出为无水印图片?超简单的操作方法看这里...
  4. 台式电脑打不开计算机c盘,电脑电脑C盘打不开怎么办(计算机应用范文)
  5. Python系统学习流程图, 教你一步步学习python
  6. golang-context
  7. oracle视图定期执行,oracle job 定时执行 存储过程
  8. iOS中书写代码规范35条小建议
  9. Ruby中对应PHP的hex2bin和bin2hex方法
  10. 彩色图像灰度化 (RGB ⇒ Gray )(RGB ⇒ YUV)(Verilog)
  11. python量化之路:获取历史某一时刻沪深上市公司股票代码及上市时间
  12. 实战:淘宝新品想抢占市场流量 分三步进行
  13. SpringCloud微服务使用Feign如何暴露接口并整合SpringBoot测试
  14. android 记录美剧观看进度,[推荐]i看美剧应用:美剧播出、新闻发生提醒直接推送到手机...
  15. USACO 2018 January Contest
  16. 程序员用软件测试原理解读蚂蚁集团上市受阻!
  17. 2020-10-18Go语言接口
  18. eos节点服务器_eos区块链php开发包
  19. CY8C5888AXQ-LP096 CY8C5888AXI-LP096,IC MCU 32BIT
  20. Windows Service 创建与安装

热门文章

  1. 东财《人力资源管理X》综合作业
  2. Springboot实验室自主预约系统毕业设计源码111953
  3. 开源摄影测量与遥感处理软件OSSIM简介
  4. python列表中的字典如何添加键值对_在Python中将键值对添加到字典中
  5. 浅谈航管二次雷达工作原理
  6. Kettle基本使用(三) —— 转换的使用
  7. _012_IDEA_idea 创建工作空间(空项目) 项目组
  8. 盘点那些恶搞C++小程序
  9. 塑料周转箱提高贮存效率
  10. 开源中国iOS客户端学习