Skip to main content
BRILLIQS

Bokeh

A Python library that produces interactive plots which run in a browser, with an optional server for Python driven behaviour.

Bokeh is a Python library for creating interactive visualisations that display in a web browser. Plots are described in Python and rendered as browser content, so panning, zooming and hovering work without writing JavaScript. A server component is also available when a plot needs to respond by running Python code.

What Bokeh is for

Bokeh is a Python library that produces interactive visualisations for a browser.

The combination is the point. Interactive charts normally mean JavaScript. Bokeh lets someone working in Python describe the plot in Python and get browser based interaction out of it, without changing language.

Building a plot from glyphs

Bokeh does not offer named chart types you configure. You create a figure and add glyphs to it.

A glyph is a visual mark: a line, a set of circles, a series of bars, a patch. A scatter plot is circles added to a figure. A line chart is a line glyph. A combined chart is both added to the same figure.

This is a little more assembly than calling for a bar chart, and it means combining marks is natural rather than a special case.

Tools

Interaction comes from tools attached to a figure. Pan, box zoom, wheel zoom, reset, selection, hover.

Which tools appear is chosen per figure, and that choice is worth making deliberately. A plot for reading a trend needs fewer tools than one meant for examining individual points, and offering every tool on every figure makes a chart harder to use rather than easier.

Shared data and linked plots

The idea that gives Bokeh much of its value is that figures can read from a shared data structure.

When two plots use the same structure, they are not independent pictures that happen to show related numbers. Selecting a set of records in one plot marks those same records in the other, because the selection belongs to the data rather than to a figure.

For exploration, that linking is often what makes a pattern visible: highlight the unusual points in one view and see immediately where they sit in another.

Two ways to deliver a plot

As a file. A plot can be saved as a standalone document. It opens in a browser with nothing running behind it, which makes it straightforward to email or publish. It can do whatever was built into it and nothing more.

Through the server. The server keeps Python running behind the plot. When a reader moves a slider or makes a selection, Python executes, recomputes and updates the figure.

The distinction decides what is possible. Filtering to data already present works in a file. Recomputing a model on the current selection needs the server.

Who uses Bokeh

Bokeh is used by Python analysts and researchers who want interactive output, and by teams building small internal tools where a full web application would be more than the task requires.

Points to consider

The server is a running process, so anything depending on it needs somewhere to run and to be looked after. A standalone file has no such requirement, and being clear about which mode a piece of work needs avoids building for one and deploying the other.

Data volume also matters. A standalone plot carries its data to the browser, so very large sets need aggregating or downsampling first, which the documentation discusses.

Getting started

The documentation includes a first steps guide that builds a plot, adds glyphs and saves it as a file, followed by sections on tools, layouts, shared data sources and the server. Producing one file based plot before introducing the server is the sensible order.

Key features of Bokeh

Capabilities described in the official documentation.

Plots written in Python

A figure is built by adding glyphs such as lines, circles and bars, all described in Python rather than JavaScript.

Interaction tools

Pan, zoom, selection and hover tools are attached to a plot, and which tools appear is chosen per figure.

A shared data source

Plots read from a data structure that several figures can share, so a selection in one is reflected in the others.

The Bokeh server

A server component runs Python in response to interaction, which allows behaviour that a static file cannot provide.

Advantages of Bokeh

Factual advantages that follow from the features above.

Interactive output without JavaScript

A Python author produces a browser based interactive plot without moving into a second language to do it.

Linked views come from shared data

Because figures can read the same data structure, selecting points in one plot highlights them in another.

Output can be a single file

A plot can be saved as a standalone document that opens in a browser without anything running behind it.

Python logic can drive the plot

With the server, an interaction can run Python and update the figure, which allows behaviour beyond preset tools.

Common use cases for Bokeh

Situations the official documentation describes this tool as being used for.

Analytics

Sharing an interactive chart as a file

A plot is exported as a standalone document so a colleague opens it in a browser with nothing to install.

Data science

Selecting points across linked plots

Two figures share a data source so highlighting a group in one shows the same records in the other.

Research

A small interactive application

The server runs Python when a control changes, recomputing what the plot displays in response.

Engineering

Exploring a large set of points

Zoom and hover tools let a reader move into a dense chart and read individual values without a new plot.

Official website

Everything on this page is based on the official documentation for Bokeh. You can read the source here.

Bokeh official documentation

Frequently asked questions about Bokeh

Answers taken from the official documentation for this tool.

No. Plots are described in Python and Bokeh generates the browser content. JavaScript is only involved if you choose to write custom callbacks, which the documentation covers as an option rather than a requirement.

A glyph is a visual mark added to a figure, such as a line, a set of circles or a series of bars. A plot is built by adding glyphs to a figure rather than by requesting a named chart type.

A saved plot file can only do what was built into it. The server keeps Python running behind the plot, so an interaction can execute code, recompute values and update the figure. It is needed when the response depends on logic rather than on a preset tool.

Figures can share the same underlying data structure. Because the selection lives with that data rather than with one figure, selecting records in one plot marks the same records everywhere the structure is used.