I am trying to code the Vicsek Model and have created arrays containing the x and y coordinates for each point at specific times. I then call the x and y values for each of the time intervals and place them in lists. The data is in the form of two lists, one for x and one for y. I am trying to animate it as follows:
fig = plt.figure()
ax = fig.add_subplot(111)
scat = plt.scatter(x, y, c = x)
scat.set_alpha(0.8)
ax.set_xlim(-L/2, L/2)
ax.set_ylim(-L/2, L/2)
def animate_frames(i, fig, scat):
a = P[i]
xi = []
yi = []
for v in range(N):
xi.append(a[v,0])
yi.append(a[v,1])
A = np.transpose([xi,yi])
scat.set_offsets((A))
return scat
animation = FuncAnimation(fig, func=animate_frames, fargs=(fig,scat), frames= tmax, interval = 1000)
plt.show()
Where P[i]
calls the array in which I have stored the x and y values of my points at each time interval i
. (there are tmax
entries in P
)
What I get is a scatter plot than then flashes to another one every so often but not an animation.
I am a beginner in Python and would be grateful for any help I could get.