简体   繁体   English

"matplotlib.animation:如何绘制动画并将其同时保存在文件中?"

[英]matplotlib.animation: how to plot an animation and save it in a file simultaneously?

With animation<\/code> from matplotlib<\/code> we can plot dynamic animations.使用matplotlib<\/code>中的animation<\/code> ,我们可以绘制动态动画。 Installing the ffmpeg<\/code> codec we can save these animations into files.安装ffmpeg<\/code>编解码器,我们可以将这些动画保存到文件中。

But how can I make both showing the animation while an algorithm is running and saving this animation into a file?但是如何在算法运行时显示动画并将动画保存到文件中?

This code (full snippet in this tutorial)<\/a> does not work for me.此代码(本教程中的完整片段)<\/a>不适用于我。 It saves the file but it does not show the animation on the fly.它会保存文件,但不会动态显示动画。

ani = animation.FuncAnimation(fig, animate, frames=300,
                          interval=interval, blit=True, init_func=init)

# save the animation as an mp4.  This requires ffmpeg or mencoder to be
# installed.  The extra_args ensure that the x264 codec is used, so that    
# the video can be embedded in html5.  You may need to adjust this for
# your system: for more information, see
# http://matplotlib.sourceforge.net/api/animation_api.html
ani.save('double_pendulum.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
plt.show()

Is the answer "not supported" still valid (i was checking the docs and searchin on the web but couldn't find a solution)? “不支持”的答案是否仍然有效(我正在检查文档并在网上搜索但找不到解决方案)?

I have the same use case where i would like to show and save an animation at the same time.我有相同的用例,我想同时显示和保存动画。 Re-running the animation to save it is no option the moment one is working with dynamic, non-predictable values (ie for simulations using a random generator), since this will not lead to the same result.在使用动态的、不可预测的值(即使用随机生成器进行模拟)时,重新运行动画以保存它是没有选择的,因为这不会导致相同的结果。

Is there a workaround?有解决方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM