Bokeh is a Python interactive visualization library that targets modern web browsers for presentation. Its goal is to provide elegant, concise construction of novel graphics in the style of D3.js, and to extend this capability with high-performance interactivity over very large or streaming datasets.
Bokeh can help anyone who would like to quickly and easily create interactive plots, dashboards, and data applications.
Bokeh runs on Python it has the following dependencies;
NumPy, Jinja2, Six, Requests, Tornado >= 4.0, PyYaml, DateUtil
If you plan on installing with Python 2.7 you will also need
All of those come with the Anaconda Python Distribution. Which you can download and install for free.
Once you have anaconda installed onto your machine then you can simply run the following in cmd.exe on Windows or terminal on Mac:
conda install bokeh
If you already have a version of Python then you can run the following in cmd.exe on Windows or terminal on Mac:
pip install bokeh
Be sure to check out the Bokeh quick start guide for several examples.
Using Bokeh in Jupyter Notebook
Here is a simple example of how to use Bokeh in Jupyter Notebook:
import numpy as np from bokeh.plotting import figure # Make Bokeh Push push output to Jupyter Notebook. from bokeh.io import push_notebook, show, output_notebook from bokeh.resources import INLINE output_notebook(resources=INLINE) # Create some data. x = np.linspace(0,2*np.pi,20) y = np.sin(x) # Create a new plot with a title and axis labels p = figure(title="Simple Line Plot in Bokeh", x_axis_label='x', y_axis_label='y') # Add a line renderer with legend and line thickness p.line(x, y, legend="Value", line_width=3) # Show the results show(p)
To use bokeh you need to launch a bokeh server and connect to it using a browser. We will use this example script (
from bokeh.models import ColumnDataSource from bokeh.plotting import figure from bokeh.io import curdoc def modify_doc(doc): """Add a plotted function to the document. Arguments: doc: A bokeh document to which elements can be added. """ x_values = range(10) y_values = [x ** 2 for x in x_values] data_source = ColumnDataSource(data=dict(x=x_values, y=y_values)) plot = figure(title="f(x) = x^2", tools="crosshair,pan,reset,save,wheel_zoom",) plot.line('x', 'y', source=data_source, line_width=3, line_alpha=0.6) doc.add_root(plot) doc.title = "Hello World" def main(): modify_doc(curdoc()) main()
To launch it you need to execute bokeh on the command line and use the
serve command to launch the server:
$ bokeh serve --show hello_world.py
--show parameter tells bokeh to open a browser window and show document defined in