You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MetPy绘制SkewT图扩展mixing lines至上层对流层报错问询

问题根因

你定义的气压列表plevs的所有元素均为字符串格式,未转换为数值格式,直接传入units.Quantity()构造带单位的数组时,底层存储的仍然是字符串类型数据,metpy内部计算混合线时需要进行数值乘法运算,字符串和浮点型数值无法参与运算,因此触发类型匹配错误。

修复方法

只需要删除plevs列表中所有数值的引号,将元素改为整数/浮点型即可,修改后的完整可运行代码如下:

import matplotlib.pyplot as plt
from metpy.plots import SkewT
from metpy.units import units

fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig)
skew.plot_moist_adiabats()
# 原代码此处元素为字符串,修改为数值类型
plevs = [1, 2, 3,
         5, 7, 10,
         20, 30, 50,
         70, 100, 125,
         150, 175, 200,
         225, 250, 300,
         350, 400, 450,
         500, 550, 600,
         650, 700, 750,
         775, 800, 825,
         850, 875, 900,
         925, 950, 975,
         1000]
plevs = units.Quantity(plevs, "hPa")
skew.plot_mixing_lines(pressure=plevs)
# 可选:手动调整y轴气压显示范围,此处设置为从地面1000hPa到1hPa高空
skew.ax.set_ylim(1000, 1)
plt.show()
补充说明

如果不需要自定义这么多气压层节点,也可以直接用numpy生成连续的气压数组,代码更简洁:

import numpy as np
plevs = np.arange(1, 1001, 25) * units.hPa

内容的提问来源于stack exchange,提问作者ClimateUnboxed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 12:36:03