Creating Interactive Visualizations with Bokeh

There have been many examples of useful and exciting data visualizations for a variety of topics and applications.

In [1]:
from IPython.display import IFrame, HTML
from IPython.core.display import display

display(IFrame("http://demographics.coopercenter.org/DotMap/index.html", '800px', '600px'))
In [2]:
display(IFrame("http://www.nytimes.com/interactive/2014/07/31/world/africa/ebola-virus-outbreak-qa.html", '800px', '600px'))

But, JavaScript

Most of these invlove directly coding JavaScript.

Not everyone enjoys writing JavaScript.

tweet

What is Bokeh?

Bokeh is a Python package for creating interactive, browser-based visualizations, and is well-suited for "big data" applications.

  • Bindings can (and have) been created for other languages.

Bokeh allows users to create interactive html visualizations without using JS.

Bokeh is a language-based visualization system. This allows for:

  • high-level commands for data binding, transformation, interaction
  • low-level power to deeply customize

Bokeh philosophy:

Make a smart choice when it is possible to do so automatically, and expose low-level capabilities when it is not.

How does Bokeh work?

Bokeh writes to a custom-built HTML5 Canvas library, which affords it high performance. This allows it to integrate with other web tools, such as Google Maps.

Bokeh plots are based on visual elements called glyphs that are bound to data objects.

A Simple Example

First we'll import the bokeh.plotting module, which defines the graphical functions and primitives.

In [3]:
import bokeh.plotting as bk

Next, we'll tell Bokeh to display its plots directly into the notebook. This will cause all of the Javascript and data to be embedded directly into the HTML of the notebook itself. (Bokeh can output straight to HTML files, or use a server, which we'll look at later.)

In [4]:
bk.output_notebook()