Bokeh 论坛上的交叉帖子:https ://discourse.bokeh.org/t/display-json-item-serialized-json-in-jupyter-notebook/7245/3
我已经使用 将我的散景图序列化为 json bokeh.embed.json_item
,如文档中所述:https ://docs.bokeh.org/en/latest/docs/reference/embed.html#bokeh.embed.json_item
我现在想在 Python(Jupyter notebook)中再次加载它。我该怎么做?该文档仅提到使用 JavaScript 加载它并将其嵌入到网页中:https ://docs.bokeh.org/en/latest/docs/user_guide/embed.html
一种方法是在 IPython 笔记本中显示一个 HTML 对象,如下所示:
from IPython.core.display import display, HTML
html_plot = f'''
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js"
crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js"
crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js"
crossorigin="anonymous"></script>
</head>
<body>
<div id="myplot"></div>
<script>
item = {plot_json}
Bokeh.embed.embed_item(item, "myplot");
</script>
</body>
'''
display(HTML(html_plot))
但是,这并不能让我恢复Figure
可以操作的散景对象。