首页 > 解决方案 > 使用 matplotlib 动画可视化 html 视频

问题描述

在我的笔记本中,我从 URL 获取一些数据,执行一些分析并进行一些绘图。
我还想使用FuncAnimationof创建一个 html 动画matplotlib.animation。所以在序言中我做

import matplotlib.animation as manim
plt.rcParams["animation.html"] = "html5"
%matplotlib inline

(别的东西...... def init()...def animate(i)...)然后

anima = manim.FuncAnimation(fig, 
                         animate, 
                         init_func=init, 
                         frames=len(ypos)-d0, 
                         interval=200, 
                         repeat=False,
                         blit=True)

为了形象化,我然后打电话给

FFMpegWriter = manim.writers['ffmpeg']
writer = FFMpegWriter(fps=15)

link = anima.to_html5_video()

from IPython.core.display import display, HTML
display(HTML(link))

因为我希望剪辑在笔记本中显示为整洁的 html 视频

虽然这在我的机器上运行良好,但在 Watson-Studio 上我收到以下错误:

RuntimeError: Requested MovieWriter (ffmpeg) not available

我已经检查了它ffmpeg以 Python 包的形式提供
!pip freeze --isolated | grep ffmpegffmpeg-python==0.2.0

问题是:我怎么知道matplotlib.animation.writers在 中使用编解码器ffmpeg-python

非常感谢所有响应者和支持者

标签: htmlhtml5-videowatson-studiomatplotlib-animation

解决方案


我们目前没有在 Watson Studio on Cloud 中预安装 ffmpeg。您提到的包ffmpeg-python只是一个 Python 包装器,但如果没有实际的 ffmpeg,它将无法工作。

您可以从 conda 安装 ffmpeg:

!conda install ffmpeg

获得笔记本所需的附加软件包的完整列表后,我建议创建一个自定义环境。然后您不必将安装命令放入实际的笔记本中。

自定义可能如下所示:

dependencies:
- ffmpeg=4.2.2
- pip
- pip:
  - ffmpeg-python==0.2.0

推荐阅读