Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Bokeh visualization library by Alex Razoumov #55
Bokeh is an open-source python library for interactive visualization in a web browser.
Where: Simon Fraser University, Burnaby Campus, Library Research Commons
Prerequisite knowledge: Entry level Python
The Bokeh library provides a nice Python (or R/Julia/Scala) interface for generating JSON objects which
Installation method #1 (if installing from scratch)
Install Anaconda python distribution from http://continuum.io/downloads. It should come with all the
Installation method #2 (if you have conda installed)
conda install pip conda install numpy conda install ipython pip install jupyter conda install bokeh # installs the dependencies as well
Optional sample data -- we won't be using it much
There are three types of output in bokeh: output_file(), output_notebook(), output_server(). First, let's
We can also run bokeh from the command line. Let's save the following script in a file scatter.py:
Run it from the command line:
$ bokeh html scatter.py $ open scatter.html
Next, let's take start jupyter notebook with "ipython notebook". In the Python code simply replace
Now let's do several panels in a single plot:
Now let's add "x_range=s1.x_range" argument to s3 = figure(...) -- this will link s1's and s3's
The next example shows "tools" argument to figure(), and how we can set colors continuously:
There are many other markers:
Other glyph functions
Now add "x_range=(0,3)" argument to p = figure(...) call.
Now let's pick up a static example from http://bokeh.pydata.org/en/latest/docs/gallery.html and paste its
Similar to bokeh.plotting interface, bokeh.charts can make statistical charts
Now replace color="blue" with color="cyl", which is another column in the dataframe.
Interactivity through Jupyter notebook widgets (does not work for output_file())
Interactivity through Bokeh widgets
Run power.py inside the ipython notebook.
Bokeh server <--> python script
We can push script's output to a session on a bokeh server. First, start the server:
$ bokeh serve
and then connect to it from a running script:
Or we can simply start the script (BOKEH APPLICATION) and attach it to the server in one command (without
$ bokeh serve --show dropNumbers.py # copy dropNumbers.py from etherpad
Let's take our file scatter.py (that we wrote before) and set n=100000 (1e5) and use
$ bokeh html scatter.py $ open scatter.html # this is the step that should be accelerated with WebGL
On my laptop I get 5s (webgl=False) vs. 2s (webgl=True) rendering time in the browser. It seems that the
Mapping geo data with Google Maps
Can put a glyph on top of google maps -- run gmap.py from the etherpad in the ipython notebook.