Bokeh is an open-sourced interactive web visualization library for Python (and other languages). It provides d3-like novel graphics, over large datasets, all without requiring any knowledge of Javascript.

It has a Matplotlib compatibility layer, and it works great with the IPython Notebook, but can also be used to generate standalone HTML.

In [1]:
%run talktools

Simple Example

Here is a simple first example. First we'll import the bokeh.plotting module, which defines the graphical functions and primitives.

In [2]:
from bokeh.plotting import *
import numpy as np
Bokeh Plot

Configuring embedded BokehJS mode.

In [3]:
x = np.linspace(-6, 6, 100)
y = np.cos(x)
circle(x, y, color="red", plot_width=500, plot_height=500)
Bokeh Plot

Bar Plot Example

Bokeh's core display model relies on composing graphical primitives which are bound to data series. This is similar in spirit to Protovis and D3, and different than most other Python plotting libraries (except for perhaps Vincent and other, newer libraries).

In [4]:
from bokeh.sampledata.autompg import autompg
grouped = autompg.groupby("yr")
mpg = grouped["mpg"]
avg = mpg.mean()
std = mpg.std()
years = np.asarray(grouped.groups.keys())
american = autompg[autompg["origin"]==1]
japanese = autompg[autompg["origin"]==3]

For each year, we want to plot the distribution of MPG within that year.

In [5]:
quad(left=years-0.4, right=years+0.4, bottom=avg-std, top=avg+std, 
circle(x=np.asarray(japanese["yr"]), y=np.asarray(japanese["mpg"]), 
       alpha=0.4, line_color="red", fill_color=None, line_width=2)
triangle(x=np.asarray(american["yr"]), y=np.asarray(american["mpg"]),
         size=8, alpha=0.4, line_color="blue", fill_color=None,
Bokeh Plot

This kind of approach can be used to generate other kinds of interesting plots, like some of the following which are available on the Bokeh web page.

(Click on any of the thumbnails to open the interactive version.)

More Information

There's a nice, comprehensive tutorial with exercises at:

For the full documentation & live examples: