Matplotlib 倒钩作为时间与高度的函数 - 未知错误

Matplotlib Barbs as a function of time vs. height - unknown error

我的数据显示 16 个不同高度的风 speed/direction。此数据以 1 分钟为间隔记录。我正在尝试创建一个二维图表,其中 y 轴为高度级别,x 轴为时间级别。

00:00, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet
00:01, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet 
00:02, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet  
...
23:58, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet 
23:59, ws_10feet, wd_10feet, ws_20feet, wd_20feet,....ws_160feet,wd_160feet 

根据这些数据,我将风速和风向分离成 2 (1440,16) 个数组,一个用于 u 分量,一个用于 v 分量。我也有 time_list,它只是一个包含 1440 个元素的列表,而我的 level_heights 是一个包含 16 个元素的一维数组。

把它们放在一起作图:

...
ax.barbs([time_list,level_heights],u,v)
...

我收到以下错误:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我不确定发生了什么或如何解决。

如果你真的想显示所有 1440 次,你将有 1440 x 16 个数据点,所以你传递给 ax.barbs() 的所有变量都应该有这些维度。

编辑: 我使用 ax.barbs() documentation 中提到的快捷方式来处理您的示例数据:

X, Y: [...] If not given, they will be generated as a uniform integer meshgrid based on the dimensions of U and V.

import numpy as np
import matplotlib.pyplot as plt

level_heights = [720, 700]
u = np.array([[ 36.10376018, -3.65789061], [ 35.96327862, -45.10811509]]) 
v = np.array([[ 36.58522244, -51.57043568], [ 36.44286749, -24.64179281]])

fig, ax = plt.subplots()
ax.barbs(u, v)

ax.set_xticks([0, 1])
ax.set_xticklabels(['start', '1 minute'])

ax.set_yticks([0, 1])
ax.set_yticklabels(level_heights);

您可能想颠倒 level_heights 的顺序以使情节更自然。