【问题标题】:Metpy: hodograph place point at specified wind data?Metpy:指定风数据处的全线图放置点?
【发布时间】:2021-05-23 21:34:45
【问题描述】:

我正在尝试将地面以上特定高度的风数据包含在大气探测的全线图中。更具体地说,我希望将 1 公里、3 公里、6 公里和 9 公里的地表风绘制为一个点。到目前为止,我刚刚实现了将它们划分为边界:

# Make an array of segment boundaries - don't forget units!
boundaries_h = [0, 1000, 3000, 6000, 9000] * units.meter

# Make a list of colors for the segments
colors_h = ['#66B2FF', '#3333FF', '#7F00FF', '#000000']

# Create a hodograph
ax_hod = inset_axes(skew.ax, '37.5%', '36.5%', loc=1)
wmax = np.concatenate((u, v))
wmax = np.max(wmax)
h = Hodograph(ax_hod, component_range=wmax.magnitude+2)
if wmax.magnitude < 20:
    h.add_grid(increment=5)
if wmax.magnitude < 40 and wmax.magnitude > 20:
    h.add_grid(increment=10)
if wmax.magnitude > 40:
    h.add_grid(increment=20)
h.plot_colormapped(u, v, z, intervals=boundaries_h, colors=colors_h)

基本上,我只想在每个段的开头和结尾点点,并带有指定高度的文本(sfc、1 公里、3 公里、6 公里、9 公里)。我怎样才能做到这一点? 顺便问一下,还有没有办法将全息图轴的标签包含在圆圈内?

【问题讨论】:

    标签: python metpy


    【解决方案1】:

    您需要手动插入这些边界点,除非您已经拥有它们。您可以使用scatter 绘制匹配的彩色点——或者如果您不希望它们着色,您可以使用plot。这应该作为上述代码的补充。

    import matplotlib.colors as mcolors
    import matplotlib.patheffects as mpatheffects
    import metpy.interpolate as mpinterpolate
    
    # Interpolate to the boundary heights
    u_pts, v_pts = mpinterpolate.interpolate_1d(boundaries_h, z, u, v)
    
    # Generate a colormap/norm to color the points with scatter
    cmap = mcolors.ListedColormap(colors_h)
    norm = mcolors.BoundaryNorm(boundaries_h.m, cmap.N)
    ax_hod.scatter(u_pts, v_pts, c=boundaries_h, cmap=cmap, norm=norm, zorder=10)
    
    # Loop over points and heights to plot text (using a path effect to
    # get outlined text that should show up better)
    for up, vp, z in zip(u_pts, v_pts, boundaries_h):
        z_str = '{:~.0f}'.format(z.to('km')) if z else 'Sfc'
        ax_hod.text(up, vp, z_str, ha='center', fontsize=12,
                    path_effects=[mpatheffects.withStroke(foreground='white', linewidth=2)],
                    zorder=12)
    
    # Change tick parameters to put the ticks and labels inside
    ax_hod.tick_params(axis='y', direction='in', pad=-20)
    ax_hod.tick_params(axis='x', direction='in', pad=-15)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      相关资源
      最近更新 更多