nc数据画风场

import xarray as xr  
import matplotlib.pyplot as plt  
import numpy as np
import geopandas as gpd   
import cartopy.crs as ccrs  
import cartopy.feature as cfeature  
  
# 加载数据集  
uwnd_ds = xr.open_dataset('D:/data/uwnd.2021.nc')  
vwnd_ds = xr.open_dataset('D:/data/vwnd.2021.nc')  
  
# 选择特定的时间  
time_sel = '2021-05-14'    
  
# 从数据集中提取u分量和v分量  
uwnd = uwnd_ds['uwnd'].sel(time=time_sel)  
vwnd = vwnd_ds['vwnd'].sel(time=time_sel)  
  
# 计算风速模  
speed = np.sqrt(uwnd**2 + vwnd**2)  
  
# 加载中国省界shapefile  
gdf = gpd.read_file('D:/data/shp文件/中国_省/中国_省2.shp')   
 # 创建一个图形和轴,使用PlateCarree投影  
fig, ax = plt.subplots(figsize=(10, 5), subplot_kw={'projection': ccrs.PlateCarree()}) 
 # 绘制省界  
gdf.boundary.plot(ax=ax, color='black', linewidth=0.5)  
 
# 添加中国的行政区划(需要额外的数据,这里只添加陆地和海岸线)  
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)  
ax.add_feature(cfeature.LAND, edgecolor='black') 
  
# 设置颜色映射  
norm = plt.Normalize(vmin=np.percentile(speed, 5), vmax=np.percentile(speed, 95))  
cmap = plt.cm.viridis  # 使用适合的颜色映射  
  
# 绘制风矢羽  
q = ax.quiver(uwnd.lon, uwnd.lat, vwnd, uwnd, speed, cmap=cmap, norm=norm,  
              scale=500, width=0.004, headwidth=3, headlength=5,  
              transform=ccrs.PlateCarree())  
  
# 添加颜色条  
plt.colorbar(q, label='Wind Speed (m/s)')  
  
# 添加其他地图元素  
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)  
ax.set_title('Wind Vectors and Speed Shadows in China on May 14, 2021')  
ax.set_extent([73, 135, 18, 53], crs=ccrs.PlateCarree())  # 设置地图范围  
  
# 显示图形  
plt.show()

 

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值