向metpy斜交线添加标签

2024-06-14 18:53:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用metpy将标签添加到skewt图上的线条。我不确定这是否可能(看看metpy的GitHub,他们似乎还没有实现这个功能)。但基本上我只想给湿绝热材料、干绝热材料和混合比贴上标签。目前,我用来调用和绘制这些函数的代码是:

# Choose temperatures for moist adiabats
t0 = units.K * np.arange(278.15, 306.15, 4)
msa = skew.plot_moist_adiabats(t0=t0, linestyles='solid', colors='lime', linewidths=1.5)
# Choose starting temperatures in Kelvin for the dry adiabats
t0 = units.K * np.arange(243.15, 443.15, 10)
skew.plot_dry_adiabats(t0=t0,
                         linestyles='solid',
                         colors='gray',
                         linewidth=1.5)

# Choose the range of pressures that the mixing ratio lines are drawn over
p = units.hPa * np.linspace(1000, 400, 7)
skew.plot_mixing_lines(w=w, p=p, colors='lime')

Tags: theforplotnpunitscolorschooseskew
1条回答
网友
1楼 · 发布于 2024-06-14 18:53:40

MetPy目前无法自动标记这些特殊行。我相信你会发现,目前有一个open issue用于此。现在,您最好的解决方案是使用ax.text方法在绘图上手动添加文本,计算行顶部的露点以定位文本:

import metpy.calc as mpcalc
from metpy.plots import SkewT
from metpy.units import units

skew = SkewT()

w = np.array([0.028, 0.024, 0.020, 0.016, 0.012, 0.008, 0.004])[:, None] * units('g/g')
p = units.hPa * np.linspace(1000, 400, 7)
skew.plot_mixing_lines(w=w, p=p, colors='lime')

# Label every third line
for val in w.flatten()[::3]:
    top_p = p[-1]
    dewpt = mpcalc.dewpoint(mpcalc.vapor_pressure(top_p, val))
    skew.ax.text(dewpt, top_p, str(val.to('g/kg').m),
                 horizontalalignment='center')

相关问题 更多 >