The tutorial is broken into several sections, which are each presented in their own notebook:
As well as some extra topic appendices:
Bokeh is an interactive visualization library that targets modern web browsers for presentation. It is good for:
And most importantly:
Bokeh is an interactive visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics, and affords high-performance interactivity over large or streaming datasets. Bokeh can help anyone who would like to quickly and easily make interactive plots, dashboards, and data applications.
# Standard imports from bokeh.io import output_notebook, show output_notebook()
# Plot a complex chart with interactive hover in a few lines of code from bokeh.models import ColumnDataSource, HoverTool from bokeh.plotting import figure from bokeh.sampledata.autompg import autompg_clean as df from bokeh.transform import factor_cmap df.cyl = df.cyl.astype(str) df.yr = df.yr.astype(str) group = df.groupby(by=['cyl', 'mfr']) source = ColumnDataSource(group) p = figure(plot_width=800, plot_height=300, title="Mean MPG by # Cylinders and Manufacturer", x_range=group, toolbar_location=None, tools="") p.xgrid.grid_line_color = None p.xaxis.axis_label = "Manufacturer grouped by # Cylinders" p.xaxis.major_label_orientation = 1.2 index_cmap = factor_cmap('cyl_mfr', palette=['#2b83ba', '#abdda4', '#ffffbf', '#fdae61', '#d7191c'], factors=sorted(df.cyl.unique()), end=1) p.vbar(x='cyl_mfr', top='mpg_mean', width=1, source=source, line_color="white", fill_color=index_cmap, hover_line_color="darkgrey", hover_fill_color=index_cmap) p.add_tools(HoverTool(tooltips=[("MPG", "@mpg_mean"), ("Cyl, Mfr", "@cyl_mfr")])) show(p)
# Create and deploy interactive data applications from IPython.display import IFrame IFrame('https://demo.bokeh.org/sliders', width=900, height=500)
from IPython.core.display import Markdown Markdown(open("README.md").read())
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
This tutorial has been tested on:
Other combinations may work also.
The quickest, easiest way to install is to use Anaconda (or Miniconda):
Anaconda should come with all the dependencies included, but you may need to update your versions.
Use the command line to create an environment and install the packages:
$ conda env create $ source activate bokeh-notebooks
NOTE: Run this in the
tutorial directory where
environment.yml file is.
Once you've got a base install, you can install the remaining dependencies with:
conda install phantomjs pillow selenium
Bokeh has a sample data download that gives us some data to build demo visualizations. To get it run the following command at your command line:
$ bokeh sampledata
or run the following from within a Python interpreter:
import bokeh.sampledata bokeh.sampledata.download()
Some optional sections require the additional packages Flask, Datashader, and Holoviews. These can be installed with:
$ conda install -c pyviz datashader holoviews flask
From this folder run jupyter notebook, and open the 00 - Introduction and Setup.ipynb notebook.
$ jupyter notebook
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 - 7.12.0 Pandas - 1.0.1 Bokeh - 1.4.0