Bokeh Tutorial

00. Introduction and Setup

What is Bokeh

Bokeh is a Data Visualization library for

  • interactive visualization in modern browsers
  • standalone HTML documents, or server-backed apps
  • capable of expressive and verstatile graphics
  • can handle large, dynamic or streaming data
  • available from python (or Scala, or R, or Julia, or...)

And most importantly:

NO JAVASCRIPT REQUIRED

What can you do with Bokeh


In [1]:
# Standard imports 

from bokeh.io import output_notebook, show
output_notebook()


Loading BokehJS ...

In [2]:
# Plot a complex chart in a single line

from bokeh.charts import Histogram
from bokeh.sampledata.iris import flowers as data

hist = Histogram(data, values="petal_length", color="species", legend="top_right", bins=12)

show(hist)



In [5]:
data.head()


Out[5]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

In [3]:
from bokeh.charts import Scatter
p = Scatter(data, x='petal_length', y='petal_width')
show(p)



In [4]:
p = Scatter(data, x='petal_length', y='petal_width', color='species', 
            legend='top_left', marker='species', title="Ejemplo Scatter")
show(p)


Getting set up


In [9]:
from IPython.core.display import Markdown
Markdown(open("README.md").read())


Out[9]:

Bokeh Tutorial

Setup

Clone or download the repo

First get local copies of the tutorial notebooks:

$ git clone https://github.com/bokeh/bokeh-notebooks.git

Or download from: https://github.com/bokeh/bokeh-notebooks/archive/master.zip

Install the dependencies

This tutorial has been tested on:

  • bokeh=0.12.0
  • pandas=0.18
  • ipython-notebook=4.0.4
  • ipywidgets=4.1.1

Other combinations may work also. Packages are available via PyPI and anaconda.org.

Installing with anaconda

Install anaconda

Anaconda should come with all the dependencies included, but you may need to update your versions.

Install with miniconda

Install miniconda.

Use the command line to create an environment and install the packages:

$ conda create -n bokeh_tutorial python=3.4
$ source activate bokeh_tutorial
$ conda install bokeh pandas ipython-notebook ipywidgets

Install with pip

We recommend creating a virtual environment.

$ pip install bokeh pandas "ipython[notebook]" ipywidgets

Get the sample data

Bokeh has a sample data download that gives us some data to build demo visualizations. To get it run:

$ bokeh sampledata

Install datashader and holoviews (optional)

Optional tutorials 11 and 12 require the datashader and holoviews packages, respectively, which can be installed with:

$ conda install -c bokeh datashader
$ conda install -c holoviews/label/dev holoviews

Run Jupyter/IPython notebook

From this folder run jupyter notebook, and open the 00-intro.ipynb notebook.

$ jupyter notebook

Setup-test, run the next cell. Hopefully you should see output that looks something like this:

IPython - 4.2.0
Pandas - 0.18.1
Bokeh - 0.12.0

If this isn't working for you, see the README.md in this directory.


In [6]:
from IPython import __version__ as ipython_version
from pandas import __version__ as pandas_version
from bokeh import __version__ as bokeh_version
print("IPython - %s" % ipython_version)
print("Pandas - %s" % pandas_version)
print("Bokeh - %s" % bokeh_version)


IPython - 4.2.0
Pandas - 0.18.1
Bokeh - 0.12.0

In [ ]: