Bokeh import json_item序列化JSON在Jupyter



散景论坛:https://discourse.bokeh.org/t/display-json-item-serialized-json-in-jupyter-notebook/7245/3

我已经使用bokeh.embed.json_item序列化我的散景图为json,如文档中所述: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对象。

从Bokeh 2.3开始,将导出的JSON重新导入到Python中仍然是一个悬而未决的问题。

相关内容

最新更新