Introduction
Bokeh is a Python visualization library that produces interactive charts and dashboards rendered in modern web browsers. Unlike static plotting libraries, Bokeh generates HTML and JavaScript output, enabling pan, zoom, hover tooltips, and linked brushing without writing any frontend code.
What Bokeh Does
- Creates interactive plots (line, bar, scatter, heatmaps, geo maps) from Python
- Renders visualizations as standalone HTML files or embeddable components
- Handles large datasets efficiently via server-side downsampling and WebGL rendering
- Supports real-time streaming data updates through the Bokeh Server
- Provides widgets (sliders, dropdowns, buttons) for building interactive dashboards
Architecture Overview
Bokeh uses a two-layer architecture. The Python layer (BokehJS model) constructs a JSON document describing glyphs, data sources, and interactions. This document is serialized and sent to BokehJS, a TypeScript library that renders the visualization using HTML5 Canvas or WebGL. The optional Bokeh Server maintains a synchronized Python-JavaScript state using WebSocket connections.
Self-Hosting & Configuration
- Install with
pip install bokehorconda install bokeh - Generate standalone HTML:
output_file("plot.html")thenshow(plot) - Run interactive apps with
bokeh serve myapp.pyfor server-backed dashboards - Embed in Jupyter notebooks with
output_notebook()for inline rendering - Deploy Bokeh Server behind Nginx or Apache with
--allow-websocket-originfor production
Key Features
- Browser-native rendering requires no plugins or desktop dependencies
- Linked plots share selections and hover across multiple views automatically
- WebGL backend handles millions of points without performance degradation
- Bokeh Server enables Python callbacks triggered by user interactions in the browser
- Exports to PNG and SVG for publication-ready static output
Comparison with Similar Tools
- Matplotlib — Static plots by default; more mature for print publications but less interactive
- Plotly — Similar interactive web plots; commercial Dash framework for dashboards
- Altair — Declarative grammar-of-graphics approach; simpler API but fewer low-level controls
- Seaborn — Statistical visualization built on Matplotlib; static output only
- D3.js — Full JavaScript control; more flexible but requires writing frontend code
FAQ
Q: Can Bokeh handle millions of data points? A: Yes. Use the WebGL backend and server-side data aggregation for large datasets without browser slowdowns.
Q: How do I embed Bokeh plots in a web application?
A: Use components() to get embeddable script and div tags, or use json_item() for framework integration with React or Vue.
Q: Does Bokeh work in Jupyter notebooks?
A: Yes. Call output_notebook() at the start and plots render inline. Interactive widgets work via Jupyter comms.
Q: Can I create geographic/map visualizations? A: Yes. Bokeh includes tile providers (OpenStreetMap, Stamen) and supports GeoJSON for choropleth and point maps.