Answer a question

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

I've tried using html from this GitHub repository.

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

And

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

None of the above have worked so far.

Thanks

Answers

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

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

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

    ![SegmentLocal](191px-Seven_segment_display-animated.gif "segment")
    
  • 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 reference (should work out of the box in your notebook):

    ![ChessUrl](https://devpress-image.s3.cn-north-1.jdcloud-oss.com/a/1a9369b36b_ChessPawnSpecialMoves.jpg "chess")
    

As an example, since stack overflow is also using markdown, last line with url reference if given exactly last mentioned line: ![ChessUrl](https://devpress-image.s3.cn-north-1.jdcloud-oss.com/a/1a9369b36b_ChessPawnSpecialMoves.jpg "chess"), but not given as code reference evaluates to:

ChessUrl

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.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐