动画散点图关于时间

时间:2021-02-11 17:01:49

标签: python matplotlib jupyter-notebook matplotlib-animation

我目前有一个数组 G = [x,y,t],其中每个空间点 (G[0][i], G[1][i]) 都有一个时间分量 t = G[2][i]。数组按时间排序。我正在尝试为散点图设置动画,以便点按时间顺序显示并且不会消失。这是我当前的代码:

from matplotlib.animation import FuncAnimation
import matplotlib.animation as animation

fig = plt.figure(figsize=(10,7))
ax = plt.subplot(111, xlim=(0,1), ylim=(0,1))

def animationUpdate(k):
    x = G[0][:k]
    y = G[1][:k]
    scat.set_offsets(np.c_[x,y])
    return scat

anim = FuncAnimation(fig, animationUpdate, frames=10, interval=100, blit=True)

我收到错误“'PathCollection' object is not iterable”,我不知道如何解决。我也不确定如何安排它,以便根据它们的时间分量显示点。我是否修改了 framesintervalFuncAnimation 部分?谢谢!

0 个答案:

没有答案