12

我想知道是否可以在同一个 IPython 笔记本中使用 Bokeh 生成静态 HTML 输出和内联图。我目前看到的是,一旦我打电话output_notebook()output_file("myfile.html")卡住使用该输出模式。例如,如果我最初使用output_notebook,则随后调用output_file不会创建输出文件。

4

2 回答 2

11

reset_output()在下一个output_notebookoutput_file调用之前至少在版本 0.10.0 中有效。

# cell 1
from bokeh.plotting import figure, show, output_notebook, output_file, reset_output
p = figure(width=300, height=300)
p.line(range(5), range(5))
output_notebook()
show(p)

# cell 2
reset_output()
output_file('foo.html')
show(p)

# cell 3
reset_output()
output_notebook()
show(p)

第一个和第三个在笔记本中显示,第二个在浏览器中显示。

于 2016-01-14T16:26:25.453 回答
0

您可以使用以下代码(改编自此处的示例)创建静态 HTML :

from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import file_html

plot = figure()
plot.circle([1,2], [3,4])

html = file_html(plot, CDN, "my plot")

with open('test.html', 'w') as f:
    f.write(html)

这与output_notebook()

于 2015-10-03T06:12:19.330 回答