Reputation: 73
I am unable to plot even the most basic of Bokeh plots in Jupyter Notebook. I had a search and can see that this was a reported problem a little over a year ago but nothing since - is it still an issue for others?
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
p = figure(plot_width=400, plot_height=400)
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=15, line_color="navy",
fill_color="orange", fill_alpha=0.5)
show(p)
I get the "BokehJS 0.12.10 successfully loaded." message, but not plot. Note that it outputs html files ok.
I've tried changing the environment variables using:
import os
os.environ['BOKEH_RESOURCES'] = 'inline'
But this has not effect either. It's bee a frustrating afternoon so any help would be appreciated!
Upvotes: 7
Views: 13601
Reputation: 34618
My guess is that your version of the notebook is too old. There is no technical path to simultaneously supporting both the new JupyterLab and classic notebook versions older than 5.0, at all. Supporting JupyterLab is an imperative, so as of recently, Bokeh can only support classic notebook 5.0 and newer. So, you can:
downgrade Bokeh (<= 0.12.8), or
updgrade Jupyter Notebook (>= 5.0), or
switch to recent JupyterLab betas. You will need to install the Jupyter extension with
jupyter labextension install jupyterlab_bokeh
Upvotes: 3
Reputation: 66
Actually this is documented: https://docs.bokeh.org/en/2.4.2/docs/user_guide/jupyter.html
import itertools
import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import push_notebook, show, output_notebook
output_notebook()
TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,hover,save"
TOOLTIPS = [
("index", "$index"),
("(x, y)", "($x, $y)"),
("radius", "@radius"),
("fill color", "$color[hex, swatch]:colors"),
("foo", "@foo"),
("bar", "@bar"),
]
N = 26 * 26
x, y = np.mgrid[0:101:4, 0:101:4].reshape((2, N))
source = ColumnDataSource(data=dict(
x=x,
y=y,
radius=np.random.random(N) * 0.4 + 1.7,
colors=np.array([(r, g, 150) for r, g in zip(50+2*x, 30+2*y)], dtype="uint8"),
foo=list(itertools.permutations("abcdef"))[:N],
bar=np.random.normal(size=N),
text=[str(i) for i in np.arange(N)],
))
p = figure(title="Hoverful Scatter", tools=TOOLS, tooltips=TOOLTIPS)
r = p.circle("x", "y", radius="radius", source=source,
fill_color="colors", fill_alpha=0.6, line_color=None)
p.hover.renderers = [r] # hover only for circles
p.text("x", "y", text="text", source=source, alpha=0.5,
text_font_size="7px", text_baseline="middle", text_align="center")
show(p, notebook_handle=True)
Upvotes: 0
Reputation: 151
Running the lines below worked for me
from bokeh.resources import INLINE
import bokeh.io
from bokeh import *
bokeh.io.output_notebook(INLINE)
Upvotes: 15