I try to animate my random walk code. I have two lists that i want to animate, peopleX and peopleY. peopleX = [[-9, 9, -18], [-10, 9, -18], [-10, 9, -18], [-10, 10, -18], [-9, 10, -17], [-10, 10, -18]] peopleY = [[-14, 16, 3], [-15, 15, 3], [-16, 15, 2], [-17, 15, 1], [-16, 16, 2], [-15, 16, 3]]
plt.style.use('seaborn')
fig = plt.figure()
ax = plt.axes(xlim=(xMin, xMax), ylim=(yMin, yMax))
line, = ax.plot([], [], lw=2)
ax.set_title('2D Random Walk', fontsize=18)
ax.set_xlabel('X', fontsize=16)
ax.set_ylabel('Y', fontsize=16)
ax.tick_params(labelsize=12)
def init():
# creating an empty plot/frame
line.set_data([], [])
return line,
xdata, ydata = peopleX, peopleY
def animate():
line.set_data(xdata, ydata)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,frames=n, interval=20, blit=True)
plt.show()
anim.save('output.gif', writer='ffmpeg')
But it doesn't shows anything. If I try to save the animation it always shows.
Please help me to solve this, thank you so much :)