动画只显示静态图片 - jupyter notebook

Animation shows only a static picture - jupyter notebook

我发现了一个有趣的 particle system that I would like to implement on jupyter notebook. So I copied the code in the file collision.py 动画并将其粘贴到我的 jupyter 笔记本上。执行代码后,我只得到一张静态图片

我尝试将魔术命令 %matplotlib inline 包括在内,但它仍然不起作用。有人知道为什么吗?

您需要将其保存为 gif 文件。然后在jupyter notebook

中打开

当我运行你展示的代码时,collision.mp4将保存在本地,我可以将它作为动画播放。 如果想运行jupyter环境下的动画,需要安装如下代码

# Jupyter lab
from IPython.display import HTML
%matplotlib inline

(Omission)

# plt.show()

# jupyter lab 
plt.close()
HTML(anim.to_html5_video())

这只是我所做工作的一个例子。请尝试 this SO answer,因为它非常有用。