This is one of the 100 recipes of the IPython Cookbook, the definitive guide to high-performance scientific computing and data science in Python.
output_notebook
in order to tell Bokeh to render plots in the IPython notebook.import numpy as np
import bokeh.plotting as bkh
bkh.output_notebook()
x = np.linspace(0., 1., 100)
y = np.cumsum(np.random.randn(100))
#bkh.line(x, y, line_width=5)
#bkh.show()
p = bkh.figure()
p.line(x=x, y=y)
bkh.show(p)
An interactive plot is rendered in the notebook. We can pan and zoom by clicking on the buttons above the plot.
from bokeh.sampledata.iris import flowers
colormap = {'setosa': 'red',
'versicolor': 'green',
'virginica': 'blue'}
flowers['color'] = flowers['species'].map(lambda x: colormap[x])
p = bkh.figure()
p.scatter(flowers["petal_length"],
flowers["petal_width"],
color=flowers["color"],
fill_alpha=0.25, size=10,)
bkh.show(p)
You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).
IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).