Written and maintained by CASRAI Editorial Board
Last updated
Bokeh is an open-source Python library designed to generate interactive data visualizations directly in modern web browsers. In academic and scientific research, Bokeh enables investigators to create dynamic scatter plots, time-series dashboards, and multi-panel figures that allow readers to pan, zoom, and inspect data points without running a Python interpreter or hosting a web server.
What it is used for in research
Research workflows increasingly demand interactive visual inspection beyond what static charts provide. Bokeh bridges the gap between scientific computing in Python and web standards (HTML5 and JavaScript) by compiling Python declarations into interactive BokehJS components. In exploratory data analysis and research dissemination, researchers use Bokeh for:
- Interactive exploratory analysis: Navigating high-dimensional datasets with linked panning and zooming across multiple subplots, making outlier detection and cluster identification faster than static image iteration.
- Self-contained supplementary figures: Exporting standalone HTML documents that contain the underlying data, layout, and styling. These interactive artifacts can be uploaded directly to research data repositories (such as Zenodo or OSF) or hosted alongside open-access journal manuscripts.
- Granular point inspection: Utilizing interactive tooltips (via the
HoverTool) to display secondary metadata—such as subject identifiers, concentration levels, sample timestamps, and genetic loci—without cluttering the main visual presentation. - High-volume data rendering: Utilizing the optional WebGL graphics backend to smoothly render plots containing tens of thousands of data points without client-side browser latency.
Unlike browser dashboards that require dedicated infrastructure, Bokeh can output entirely static HTML files where all visualization logic runs client-side. When combined with scientific pipelines utilizing tools described in our data analysis tool in Python guide and binary formats in h5py, Bokeh provides an accessible pathway for interactive dissemination.
Install or access (official source only)
Bokeh is distributed through official Python package repositories and package managers. It is officially supported and continuously tested on CPython 3.12 and newer versions.
Installing via pip
To install the core Bokeh package from the Python Package Index (PyPI), execute the following command in your terminal or virtual environment:
pip install bokeh
To install optional dependency sets that support sample datasets and enhanced export capabilities, install the extended bundle:
pip install "bokeh[all]"
Installing via conda
For scientific computing environments managed through Anaconda or Miniconda, install Bokeh from the default conda channels or directly from the official Bokeh channel:
conda install bokeh
Or specifically targeting the official channel:
conda install -c bokeh bokeh
Verifying installation
You can verify that Bokeh and its core dependencies are installed correctly by running the command-line diagnostic tool:
bokeh info
This command prints the active Bokeh version, Python environment paths, and status of optional dependencies such as NumPy and pandas.
Step-by-step task
This worked example demonstrates how to build an interactive multi-sample experimental scatter plot with custom hover tooltips and export it as an independent HTML file.
1. Import required plotting modules
Import the core canvas constructor (figure), output handlers (output_file, show), data structure (ColumnDataSource), and hover inspection tool (HoverTool):
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource, HoverTool
2. Configure the standalone HTML output
Designate the destination HTML file name and browser window title. Bokeh writes the complete HTML document and embedded BokehJS runtime to this file when rendering:
output_file("experiment_results.html", title="Assay Dose-Response Visualization")
3. Structure experimental data in a ColumnDataSource
The ColumnDataSource is Bokeh’s primary data mapping object. It maps column names to arrays, lists, or pandas Series, ensuring synchronized metadata handling across renderers:
data = {
"dose": [0.1, 0.5, 1.0, 2.5, 5.0, 10.0, 25.0, 50.0],
"response": [4.2, 12.8, 25.6, 51.3, 73.1, 88.4, 94.2, 97.8],
"sample_id": ["SMP-01", "SMP-02", "SMP-03", "SMP-04", "SMP-05", "SMP-06", "SMP-07", "SMP-08"],
"replicate": ["A1", "A2", "B1", "B2", "C1", "C2", "D1", "D2"]
}
source = ColumnDataSource(data=data)
4. Initialize the figure canvas and tools
Instantiate a figure canvas object, defining plot dimensions, axis titles, log-scale transformations if applicable, and standard toolbar controls:
p = figure(
title="In Vitro Dose-Response Curve",
x_axis_label="Dose (µM)",
y_axis_label="Inhibition Response (%)",
width=700,
height=450,
tools="pan,box_zoom,wheel_zoom,reset,save"
)
5. Add glyph renderers and interactive hover tooltips
Attach a line renderer to illustrate the fitted trend and circle glyphs to represent individual sample observations. Then configure a HoverTool that references data columns using the @ prefix:
# Add trendline and observation markers
p.line(x="dose", y="response", source=source, line_width=2, color="#1f77b4", legend_label="Mean Fit")
p.circle(x="dose", y="response", source=source, size=10, fill_color="#ff7f0e", line_color="#333333", legend_label="Observations")
# Configure inspection tooltips
hover = HoverTool(tooltips=[
("Sample ID", "@sample_id"),
("Replicate", "@replicate"),
("Dose", "@dose µM"),
("Response", "@response%")
])
p.add_tools(hover)
# Position the legend
p.legend.location = "bottom_right"
p.legend.click_policy = "hide"
6. Build and render the visualization
Execute show(p) to write the standalone HTML document and automatically launch it in your default desktop browser:
show(p)
Output and how to read it
When the execution script finishes, Bokeh creates an HTML file containing HTML5 Canvas elements and embedded data structures. Here is how to navigate and interpret the generated output:
- Interactive toolbar: Located along the side or top of the figure, the toolbar contains pan, box zoom, wheel zoom, reset, and save tools. Clicking the Save icon exports the current canvas view directly as a raster PNG file.
- Dynamic hover inspection: Moving the mouse cursor over any circular marker exposes a floating tooltip showing the exact measured dose, response percentage, replicate tag, and sample identifier without permanently obscuring neighboring points.
- Interactive legend toggling: Because
click_policy = "hide"was configured, clicking an entry in the figure legend temporarily hides or reveals that specific data series, allowing researchers to evaluate overlapping curves in complex multi-cohort trials. - Portability: The exported HTML file is completely standalone. It can be sent via email, opened by collaborators who do not have Python installed, or embedded into web pages using standard HTML
iframeelements.
Troubleshooting
Researchers encountering issues when configuring or deploying Bokeh plots can resolve common errors using the following diagnostic checks:
| Issue | Underlying Cause | Resolution |
|---|---|---|
| Blank plot in Jupyter Notebook | Missing inline notebook communication initialization. | Call from bokeh.io import output_notebook; output_notebook() in an initial cell before executing show(). |
| Slow panning with large arrays (>50,000 points) | Default 2D Canvas rendering overhead for high-vertex counts. | Enable WebGL hardware acceleration by specifying output_backend="webgl" inside the figure() constructor. |
Hover tool displays ??? |
Tooltip field name does not match a column in the ColumnDataSource. |
Verify that the tooltip string matches the exact dictionary key, using @column_name syntax. |
| CORS or script blocking in local browser | Strict local file protocol restrictions (file://) blocking CDN script loading. |
Set output_file("plot.html", mode="inline") to embed BokehJS directly within the HTML file rather than referencing remote CDN scripts. |
| Static PNG export fails | Missing headless browser driver dependencies. | Install the export bundle (pip install "bokeh[all]") and install a headless WebDriver such as playwright or selenium with appropriate browser binaries. |
Free alternatives
Python offers several mature, open-source visualization libraries. Choosing the appropriate tool depends on whether your project requires static publication figures, grammar-of-graphics abstractions, or server-backed dashboards. For deeper comparisons between static and interactive tools, see our Plotly vs Matplotlib comparison, Seaborn vs Matplotlib guide, and scatter plot in Python tutorial.
| Library | License | Primary Focus | Interactivity Model | Best Research Use Case |
|---|---|---|---|---|
| Bokeh | BSD 3-Clause | Web-native interactive plots and dashboards | Client-side JavaScript (BokehJS) or Python server callbacks | Interactive data exploration, standalone HTML supplementary figures, and multi-panel research dashboards. |
| Matplotlib | PSF-based | Publication-quality static 2D figures | Static by default; basic GUI event handling in desktop backends | Print journal manuscripts, camera-ready raster and vector graphics (PDF/EPS). Check our guide on pip install matplotlib for setup details. |
| Plotly (Python) | MIT | Web-first interactive charts and Dash apps | Declarative JSON specifications rendered via Plotly.js | Rapid creation of interactive 3D plots, financial figures, and complex Dash web applications. |
| Altair | BSD 3-Clause | Declarative statistical visualization based on Vega-Lite | Client-side Vega-Lite runtime interactions | Rapid exploratory analysis of structured tabular data using concise declarative syntax. |
| Seaborn | BSD 3-Clause | Statistical data visualization built on Matplotlib | Static graphics with high-level statistical aggregation | Automated calculation of confidence intervals, regression fits, and multi-variable distribution plots. |
FAQ
Is Bokeh free and open source for academic research?
Yes. Bokeh is licensed under the permissive BSD 3-Clause License and is a community-supported NumFOCUS sponsored project. It is free to use, modify, and distribute for academic, governmental, and commercial research without licensing fees or seat limitations.
Can I export Bokeh plots for print manuscripts?
Yes. Bokeh includes the export_png() and export_svg() utility functions in bokeh.io. Exporting high-resolution vector SVG or raster PNG files requires installing headless browser utilities (such as Playwright or Selenium) to render the canvas before saving.
Does Bokeh require an active internet connection to view generated HTML files?
By default, Bokeh generates HTML files that reference BokehJS libraries hosted on a content delivery network (CDN). However, you can configure fully offline viewing by setting mode="inline" inside output_file(), which embeds the complete JavaScript and CSS assets directly inside the HTML document.
How does Bokeh differ from Plotly for scientific data?
Both libraries generate browser-based interactive visualizations. Bokeh uses an explicit canvas and glyph architecture modeled on graphics primitives (circles, patches, lines), providing fine-grained control over low-level visual geometry and custom WebGL pipelines. Plotly uses a declarative schema oriented around higher-level trace types and Dash application integration.
Sources
- Bokeh Documentation: First Steps & Quickstart. Bokeh Project. URL:
https://docs.bokeh.org/en/latest/docs/first_steps.html. Checked 2026-11-08. - Bokeh Documentation: Installation Guide and Environment Requirements. Bokeh Project. URL:
https://docs.bokeh.org/en/latest/docs/first_steps/installation.html. Checked 2026-11-08. - Bokeh User Guide: Basic Data Mapping and ColumnDataSource. Bokeh Project. URL:
https://docs.bokeh.org/en/latest/docs/user_guide/basic/data.html. Checked 2026-11-08. - Python Package Index (PyPI): Bokeh Package Metadata and Release Details. Python Software Foundation. URL:
https://pypi.org/project/bokeh/. Checked 2026-11-08.







