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.
%run talktools
Here is a simple first example. First we'll import the bokeh.plotting
module, which defines the graphical functions and primitives.
from bokeh.plotting import *
output_notebook()
import numpy as np
Configuring embedded BokehJS mode.
x = np.linspace(-6, 6, 100)
y = np.cos(x)
circle(x, y, color="red", plot_width=500, plot_height=500)
show()
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).
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.
hold(True)
figure()
quad(left=years-0.4, right=years+0.4, bottom=avg-std, top=avg+std,
fill_alpha=0.4)
circle(x=np.asarray(japanese["yr"]), y=np.asarray(japanese["mpg"]),
size=8,
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,
line_width=2)
hold(False)
show()
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.)
There's a nice, comprehensive tutorial with exercises at: http://bokeh.pydata.org/tutorial/index.html
For the full documentation & live examples: http://bokeh.pydata.org