I would like to make a video with some car traffic. For this I have all state information of all cars. Drawing the situation for a given time is no problem. Animation is. I made some code that looks like the code below but this does not work: nothing is moving. I do not understand the basics of animation. Can someone point me in the right direction?
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.animation as manimation
FFMpegWriter = manimation.writers['ffmpeg']
writer = FFMpegWriter(fps=10)
def animate_traffic():
fig=plt.figure(1)
ax=fig.add_subplot(1,1,1)
tsim=tstart
with writer.saving(fig, "roadtest.mp4", 100):
for i in range(100):
draw_roadlayout()
for car in cars:
# draw each of the cars on the road
# based on time tsim
plt.grid(False)
ax.axis(plt_area)
fig = plt.gcf()
writer.grab_frame()
ax.cla()
tsim+=timestep
plt.close(1)
Thank you.
updated: after writing, I clear the area. The full version works for me now.