Bokeh plots and Kyso
Use this snippet to make bokeh plots work seamlessly in Jupyter and Kyso.
To make bokeh plots work inside Jupyter and render in Kyso, we will save the plot to a virtual html file and show it
1
from bokeh.plotting import figure, output_file, save
2
from IPython.display import IFrame
3
from IPython.core.display import display, HTML
4
import tempfile
5
6
def bokeh_show(plot):
7
tmp_output_filename = tempfile.NamedTemporaryFile(suffix='.html').name
8
output_file(tmp_output_filename)
9
save(plot)
10
11
f = open(tmp_output_filename, "r")
12
display(HTML(f.read()))
Copied!
Then we can use this function bokeh_show to show any plots we create
1
p = figure(title="Bokeh test", plot_width=300, plot_height=300)
2
p.circle([1, 2], [3, 4])
3
4
bokeh_show(p)
Copied!
Last modified 6mo ago
Copy link