0

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.

MovieWriter stderr: [gif @ 0000023501dad280] GIF muxer supports only a single video GIF stream. Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument Error initializing output stream 0:0 --

Please help me to solve this, thank you so much :)

Tiffany Arasya
  • 99
  • 1
  • 1
  • 9
  • Could you provide a full example, or at least the shape of `peopleX` and `peopleY`? The first problem I see is that you always use the same data in `animate`, i.e., you would not get an animation. – TheIdealis Apr 28 '20 at 14:36
  • both of them same like that. 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]] – Tiffany Arasya Apr 28 '20 at 15:47

0 Answers0