如何在Jupyter笔记本中嵌入gif? [英] How do I embed a gif in Jupyter notebook?

查看:421
本文介绍了如何在Jupyter笔记本中嵌入gif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在Jupyter笔记本中显示gif,但遇到了一些麻烦.我不断得到一个空白的图像文件.

I've been trying to display a gif in Jupyter notebook and have had some trouble. I keep getting a blank image file.

我尝试使用此GitHub存储库中的html .

![wignerfunction][1](../gifs/wigner_rotation_animate.gif "wigner")

还有

from IPython.display import Image
Image(url='example.gif')  

到目前为止,以上方法均无效.

None of the above have worked so far.

谢谢

推荐答案

我一直试图在Jupyter笔记本中显示gif,但遇到了一些麻烦.

I've been trying to display a gif in Jupyter notebook and have had some trouble.

要在笔记本中显示gif,可以在Markdown单元格上使用内联标记,如下所示:

To display gif in notebook you can use inline markup on a Markdown cell like this:

  • 与ipynb笔记本文件相同的文件夹中的相对引用:

  • Relative reference in the same folder as ipynb notebook file:

![SegmentLocal](191px-Seven_segment_display-animated.gif "segment")

  • 子文件夹图像中ipynb笔记本文件所在的文件夹中的相对引用:

  • Relative reference in subfolder images from folder where ipynb notebook file is:

    ![SegmentLocal](images/191px-Seven_segment_display-animated.gif "segment")
    

  • 来自根文件夹的绝对引用,与笔记本文件的位置无关:

  • Absolute reference from root folder irrespective of location of notebook file:

    ![SegmentLocal](/Users/username/some-folder/191px-Seven_segment_display-animated.gif "segment")
    

  • URL参考(应该在笔记本中开箱即可使用):

  • URL reference (should work out of the box in your notebook):

    ![ChessUrl](https://upload.wikimedia.org/wikipedia/commons/7/71/ChessPawnSpecialMoves.gif "chess")
    

  • 作为示例,由于堆栈溢出也使用markdown,因此如果给出的URL的最后一行恰好在最后提到的行:![ChessUrl](https://upload.wikimedia.org/wikipedia/commons/7/71/ChessPawnSpecialMoves.gif "chess"),但未作为代码引用给出,则计算为:

    As an example, since stack overflow is also using markdown, last line with url reference if given exactly last mentioned line: ![ChessUrl](https://upload.wikimedia.org/wikipedia/commons/7/71/ChessPawnSpecialMoves.gif "chess"), but not given as code reference evaluates to:

    在Jupyter笔记本中也应显示.现在,如果您可以看到最后一个确定,但无法从引用的本地文件中看到它,则很可能是gif损坏,权限问题或文件路径不正确.

    As should be displayed in your jupyter notebook as well. Now, if you can see this last one ok, but can't see it from referenced local file you are most probably either having corrupted gif, permission issues or not proper file path.

    这篇关于如何在Jupyter笔记本中嵌入gif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆