如何将gif图片添加到Jupyter Notebook
How to add gif image to Jupyter Notebook
我正在尝试 link 使用网站提供的 iframe 和 JS 脚本对 Jupyter notebook 进行可视化:https://public.flourish.studio/visualisation/1631776/ 但在 notebook 中出现无效语法错误。
我试过如下,有什么问题吗?
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 存储库加载相同的 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
为 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 图片放入 markdown 单元格,请使用:

我正在尝试 link 使用网站提供的 iframe 和 JS 脚本对 Jupyter notebook 进行可视化:https://public.flourish.studio/visualisation/1631776/ 但在 notebook 中出现无效语法错误。
我试过如下,有什么问题吗?
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 存储库加载相同的 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
为 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 图片放入 markdown 单元格,请使用:
