I am using google colab and would like to embed a gif. Does anyone know how to do this? I am using the code below and it is not animating the gif in the notebook. I would like the notebook to be interactive so that one can see what the code animates without having to run it.
I found many ways to do so that did not work in Google colab. The code and the GIF of interest is below.
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread("/content/animationBrownianMotion2d.gif")
plt.imshow(img)
I tried some of the solutions provided.
import IPython
from IPython.display import Image
Image(filename='/content/animationBrownianMotion2d.gif')
and similarly
import IPython
from IPython.display import Image
Image(filename='/content/animationBrownianMotion2d.gif',embed=True)
but got the error,
---------------------------------------------------------------------------
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
both times.