我正在尝试创建一个动画来显示多个粒子的移动。在
我在这里找到了一个粒子阵列的答案(如果我能从其中一个粒子阵列中找到答案的话)。在import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
positions = np.array([[2,2],[3,3],[4,4]])
def init():
scatterplot.set_offsets([[], []])
return [scatterplot]
def update(i, scatterplot, positions):
scatterplot.set_offsets(positions[i])
return [scatterplot]
fig = plt.figure()
scatterplot = plt.scatter([], [], s=100)
plt.xlim(0,5)
plt.ylim(0,5)
anim = animation.FuncAnimation(
fig, update, init_func=init, fargs=(scatterplot, positions), interval=1000, frames=3,
blit=True, repeat=True)
plt.show()
但是我不知道如何在同一个动画中添加更多的粒子。
假设我要添加第二个带有位置的粒子
^{pr2}$
我又是怎么做到的呢?在
我是一个matplotlib新手,一直在google上疯狂搜索都没有用,非常感谢您的帮助:)
编辑:
我最终解决了,只是正确格式化数据的问题。在positions = np.array([[[2,2],[2,1]],[[3,3],[3,2]],[[4,4],[4,3]]])
如果数组包含第一步中的所有位置,那么第二步中的所有位置等都起作用。
我更希望得到一个彩色公关活动点,以保持他们的跟踪,但至少现在它工作。在