【发布时间】:2020-07-21 10:12:47
【问题描述】:
我正在使用 google colab 并想嵌入一个 gif。有谁知道如何做到这一点?我正在使用下面的代码,它没有为笔记本中的 gif 设置动画。我希望笔记本是交互式的,这样人们就可以看到代码动画的内容,而无需运行它。
我发现了许多在 Google colab 中不起作用的方法。下面是代码和感兴趣的 GIF。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread("/content/animationBrownianMotion2d.gif")
plt.imshow(img)
我尝试了提供的一些解决方案。
import IPython
from IPython.display import Image
Image(filename='/content/animationBrownianMotion2d.gif')
类似
import IPython
from IPython.display import Image
Image(filename='/content/animationBrownianMotion2d.gif',embed=True)
但得到了错误,
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-27-56bf6cd2b134> in <module>()
1 import IPython
2 from IPython.display import Image
----> 3 Image(filename='/content/animationBrownianMotion2d.gif',embed=True)
4
/usr/local/lib/python3.6/dist-packages/IPython/core/display.py in __init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata)
1013
1014 if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS:
-> 1015 raise ValueError("Cannot embed the '%s' image format" % (self.format))
1016 self.width = width
1017 self.height = height
ValueError: Cannot embed the 'gif' image format
两次。
【问题讨论】:
标签: python matplotlib jupyter-notebook gif google-colaboratory