我想制作一些汽车流量的视频。为此我拥有所有汽车的所有状态信息。在特定时间绘制情况是没有问题的。动画是。我做了一些代码,看起来像下面的代码,但这不起作用:没有任何东西在移动。我不明白动画的基础知识。有人能指引我朝着正确的方向吗?使用matplotlib动画流量
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)
谢谢。
已更新:写完后,我清除该区域。完整版现在适合我。
http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/ – tacaswell
http://stackoverflow.com/questions/4092927/generating-movie-from-python-without-保存个人文件到文件/ 13983801#13983801 – tacaswell
http://stackoverflow.com/questions/19519587/python-matplotlib-plot-multi-lines-array-and-animation/19521738#19521738 – tacaswell