我一直试图在Jupyter notebook中显示一个gif,但遇到了一些问题。我一直得到一个空白的图像文件。
我尝试过使用this GitHub repository中的html。
![wignerfunction][1](../gifs/wigner_rotation_animate.gif "wigner")
和
from IPython.display import Image
Image(url='example.gif')
到目前为止,上述方法都没有奏效。
谢谢
发布于 2020-03-05 22:40:41
当我需要在jupyter笔记本中包含gif动画时,我会执行以下操作:
<img src="FileName.gif" width="750" align="center">
宽度和对齐参数由您定义。
谢谢
发布于 2022-02-25 07:43:28
在某些情况下,您需要在Jupyter notebook中嵌入gif文件,也就是说,即使磁盘上的gif文件已被删除,gif也可以在Jupyter notebook中工作。@user13013261的解决方案将失败,并且@Const的解决方案只能在Markdown单元格中工作。
你可以尝试这些:
display(Image(data=open(gif_path,'rb').read(), format='png'))
或
import base64
b64 = base64.b64encode(open(gif_path,'rb').read()).decode('ascii')
display(HTML(f'<img src="data:image/gif;base64,{b64}" />'))
参考资料:
https://github.com/ipython/ipython/issues/10045#issuecomment-318202267 https://github.com/ipython/ipython/issues/10045#issuecomment-642640541
发布于 2020-01-30 22:29:32
任何图像格式,无论是png,jpg,jpeg或gif等,你想要在python jupyter笔记本中显示,然后简单地使用matplotlib库。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread("/home/gaurav/assignment/sofcomputing/river.gif")
plt.imshow(img)
https://stackoverflow.com/questions/51527868
复制相似问题