【问题标题】:Cartopy barbs not working properlyCartopy 倒钩无法正常工作
【发布时间】:2018-04-12 00:21:50
【问题描述】:

我正在尝试绘制北太平洋投影上的 250 hPa 位势高度、1000 hPa 可降水量和 250 hPa 风。尝试使用倒钩时,我没有收到错误消息,但倒钩并没有实际显示在地图上。我认为这可能与将我的数据投影到 cartopy 投影上有关,但我对 cartopy 很陌生,不太了解发生了什么。如果有人注意到我的预测总体上被搞砸了,我不会介意一些方向。谢谢!

def plotMap():

    proj = ccrs.LambertConformal(central_longitude=-165, central_latitude=30, standard_parallels=[53])

    fig, ax = plt.subplots(subplot_kw=dict(projection=proj))   

    ax.set_extent([235 ,160 , 5, 60], crs=ccrs.PlateCarree())    
    ax.add_feature(cfeature.LAND, facecolor='0.9') 
    ax.add_feature(cfeature.LAKES, alpha=0.9)  
    ax.add_feature(cfeature.BORDERS, zorder=10)
    ax.add_feature(cfeature.COASTLINE, zorder=10)

    states_provinces = cfeature.NaturalEarthFeature(category='cultural',  
    name='admin_1_states_provinces_lines', scale='50m', facecolor='none')

    ax.add_feature(states_provinces, edgecolor='gray', zorder=10)

    ax.gridlines(xlocs=np.arange(0,361,20), ylocs=np.arange(-80,90,20)) 

    return fig, ax

fig, ax = plotMap()




hght_levels = np.arange(9500,11250,250)
hght_contour=ax.contour(lon, lat, g, colors='k', levels=hght_levels, 
linewidths=1, zorder=3, transform = ccrs.PlateCarree())

wind_levels = np.arange(0, 110, 10)
wind_contour = ax.contour(lon, lat, wind, levels = wind_levels, 
linewidths=5, zorder=0.8, transform = ccrs.PlateCarree())

pwat_levels = np.linspace(0, 50, 9)
pwat_contour = ax.contourf(lon, lat, pwat, levels = pwat_levels,  
                       cmap=plt.cm.plasma, zorder=1.0, transform = 
ccrs.PlateCarree())
cb = plt.colorbar(pwat_contour, shrink=0.5)
cb.set_ticklabels(pwat_levels)

urel = u.values*1.944
vrel = v.values*1.944
ax.barbs(lon, lat, urel, vrel, regrid_shape=12 transform=ccrs.LambertConformal())

plt.clabel(hght_contour, hght_levels, zorder=20, inline=1,inline_spacing=3, 
fmt='%1i', fontsize=12)


fig

The plot

【问题讨论】:

    标签: python matplotlib cartopy


    【解决方案1】:

    您对调用barbs 的投影将transform 参数作为LambertConformal(),但看起来您正在传递位置的纬度和经度值。将transform 更改为PlateCarree(),就像您在其他绘图方法中使用的那样。

    【讨论】:

    • 这行得通,但它绘制了太多倒钩,以至于您看不到数据。我尝试使用 regrid_shape 并将其设置为各种值,但我不断收到错误消息:QH6019 qhull 输入错误:无法缩放最后一个坐标。输入是同圆或同球的。
    • 我不确定regrid_shape,但我通常的解决方案是:ax.barbs(lon[::5, ::5], lat[::5, ::5], urel[::5, ::5], vrel[::5, ::5], transform=ccrs.LambertConformal())
    • 我尝试实施您的建议并得到错误:数组索引过多。不知道为什么这么难,没有多大意义。
    • 如果它是 lon/lat 的一维数组,那么你应该这样做:ax.barbs(lon[::5], lat[::5], urel[::5, ::5], vrel[::5, ::5], transform=ccrs.LambertConformal())。您必须查看数据布局的详细信息(一维、二维等)才能正确处理。
    • 谢谢!这行得通。你介意解释一下这是做什么的吗?我对编码还不是很熟悉,我相信你也知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多