【问题标题】:How to add gif image to Jupyter Notebook如何将 gif 图像添加到 Jupyter Notebook
【发布时间】:2020-07-02 17:52:14
【问题描述】:

我正在尝试使用网站提供的 iframe 和 JS 脚本将可视化链接到 Jupyter 笔记本:https://public.flourish.studio/visualisation/1631776/,但在笔记本中出现无效语法错误。

我已经尝试如下,关于问题的任何想法?

from IPython.display import display, HTML
js = "<div class="flourish-embed flourish-bar-chart-race" data-src="visualisation/1631776"> 
<script src="https://public.flourish.studio/resources/embed.js"></script></div>"
display(HTML(js))

错误:

File "<ipython-input-4-5d8ce592337a>", line 2
js = "<div class="flourish-embed flourish-bar-chart-race" data-src="visualisation/1631776"><script src="https://public.flourish.studio/resources/embed.js"></script></div>"
                         ^
SyntaxError: invalid syntax

注意:我也尝试从 git repo 加载相同的 gif,如下所示,但出现超时错误:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread("https://github.com/rsyed1/kaggle/blob/master/Cases2020.gif?raw=true")
plt.imshow(img)

错误:

gaierror                                  Traceback (most recent call last)
/opt/conda/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1317                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1318                           encode_chunked=req.has_header('Transfer-encoding'))
1319             except OSError as err: # timeout error

【问题讨论】:

    标签: javascript python-3.x jupyter-notebook gif


    【解决方案1】:

    为 iframe 尝试以下操作:

    import IPython
    url = "https://public.flourish.studio/visualisation/1631776/"
    iframe = '<iframe src=' + url + ' width=700 height=350></iframe>'
    IPython.display.HTML(iframe)
    

    忽略警告,因为它建议的版本目前不起作用。


    使用代码显示gif:

    from IPython.display import Image
    Image("https://raw.githubusercontent.com/rsyed1/kaggle/master/Cases2020.gif")
    

    要将您的 gif 图像放置在 ma​​rkdown 单元格中,请使用:

    ![display image](https://raw.githubusercontent.com/rsyed1/kaggle/master/Cases2020.gif)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      • 2012-09-03
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多