Matplotlib 多个移动对象的动画

Matplotlib 多个移动对象的动画,matplotlib,jquery-animate,Matplotlib,Jquery Animate,我在Python Jupyter笔记本中工作。我有一个矩阵v,它包含N个时间步的NN粒子的速度。我想创建一个动画,其中所有P粒子的速度都以时间表示。此外,应添加颜色条;在动画期间,每个粒子的颜色应该是速度的度量值。 现在我试过这个: %matplotlib notebook v = np.random.rand(NN,N) x0 = np.random.rand(NN) x = (x0') * ones(1, N) fig = plt.figure() ax = plt.axes(xlim=(-

我在Python Jupyter笔记本中工作。我有一个矩阵v,它包含N个时间步的NN粒子的速度。我想创建一个动画,其中所有P粒子的速度都以时间表示。此外,应添加颜色条;在动画期间,每个粒子的颜色应该是速度的度量值。 现在我试过这个:

%matplotlib notebook
v = np.random.rand(NN,N)
x0 = np.random.rand(NN)
x = (x0') * ones(1, N)
fig = plt.figure()
ax = plt.axes(xlim=(-1, 6))
line, = ax.plot([],[], lw=2)
for j in range(NN):
    line, = plt.plot(x[j,:], v[j,:])

def init():
    line.set_data([], [])
    return line,
ti = np.linspace(0,N,dt)
def animate(i):
    for j in range(NN):
        line, = plt.plot(x[j,:ti], v[j,:ti],'ro')
    return line,

anim = animation.FuncAnimation(fig, animate, init_func=init, blit=True)
我希望有人能帮助我在这方面走得更远