如何使用Matplotlib或其他方法在动画图中绘制不规则采样的时间数据?

问题描述 投票:0回答:1

我有不规则时间步骤记录的数据,我希望随着时间的推移将其显示为滚动动画。例如,数据A可以具有时间点[0.001,0.004,0.007,0.009,...,0.97],并且数据B可以在每个点处具有大致相同的正负0.02。

我想创建一个随时间更新的数据的滚动动画,但只有在该顶点的时间过去之后才更新一条线的点/顶点。我想不出一个好的方法让numpy说“对于这一行,只计算这个时间戳上的数据”。我想如果我能得到它,我可以从matplotlib示例中找到一些东西,但完整的解决方案也会很好。

谢谢!

numpy matplotlib animation
1个回答
0
投票

我认为一种解决方案是将数据映射为一致的格式:

A = np.array([1, 1.5, 4.5, 5])
B = np.array([1, 2.5, 3.5, 5])

scroll = np.linspace(1,5,11)
A_idx = np.searchsorted(A, scroll) 
B_idx = np.searchsorted(B, scroll)

>>> scroll
array([1. , 1.4, 1.8, 2.2, 2.6, 3. , 3.4, 3.8, 4.2, 4.6, 5. ])
>>> A[A_idx]
array([1. , 1.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 5. , 5. ])
>>> B[B_idx]
array([1. , 2.5, 2.5, 2.5, 3.5, 3.5, 3.5, 5. , 5. , 5. , 5. ])

您可能需要小心使用前视或后视值(这里是前瞻性的),但它会在新数据可用时更新。

© www.soinside.com 2019 - 2024. All rights reserved.