python - 如何在 Jupyter notebook 中嵌入 gif?

标签 python ipython jupyter

我一直在尝试在 Jupyter notebook 中显示 gif,但遇到了一些麻烦。我一直收到一个空白图像文件。

我尝试使用来自 this GitHub repository 的 html .

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

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

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

谢谢

最佳答案

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

要在笔记本中显示 gif,您可以像这样在 Markdown 单元格上使用内联标记:

  • ipynb notebook文件所在文件夹的相对引用:

    ![SegmentLocal](191px-Seven_segment_display-animated.gif "segment")
    
  • ipynb 笔记本文件所在文件夹的子文件夹图像中的相对引用:

    ![SegmentLocal](images/191px-Seven_segment_display-animated.gif "segment")
    
  • 无论笔记本文件的位置如何,从根文件夹绝对引用:

    ![SegmentLocal](/Users/username/some-folder/191px-Seven_segment_display-animated.gif "segment")
    
  • URL 引用(应该在您的笔记本中开箱即用):

    ![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"),但未作为代码引用计算得出:

ChessUrl

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

关于python - 如何在 Jupyter notebook 中嵌入 gif?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51527868/

相关文章:

python - 在 numpy 中对大型 3D 图像进行下采样

python - 使用 Python 的 PIL,如何增强图像的对比度/饱和度?

linux - 通过 Google Colab 进行 x11 转发

Matplotlib Python 内联开/关

ipython - 更改 IPython/Jupyter 笔记本工作目录

google-bigquery - 使用 BigQuery Jupyter 魔术命令时,将 Python 环境中的变量添加到查询中

python-3.x - 如何在 jupyter notebook markdown 中编写分段函数?

python - (psycopg2.OperationalError) 无效 - 操作码

python - SQLAlchemy 连接池问题 - Windows 上的 Postgres

python - IPython `display` 到字符串