Bokeh
Bokeh is an interactive visualization library for modern web browsers. It helps create versatile, interactive plots, dashboards, and data applications from Python, targeting web browsers for rendering. It is currently at version 3.9.0 and typically releases minor versions every few months with major versions less frequently.
Warnings
- breaking Bokeh 3.x introduced significant breaking changes, most notably the removal of `output_file()`, `output_notebook()`, and `output_server()`. The `show()` function now handles output implicitly based on the environment (e.g., Jupyter, script).
- gotcha For interactive features like callbacks, linked panning, or dynamic updates, data should be stored in a `ColumnDataSource`. Direct Python lists or NumPy arrays are static and will not update interactively without manual re-rendering.
- gotcha Building Bokeh server applications (`bokeh serve`) requires specific structuring using `curdoc()` and callbacks, and cannot be run like a standard Python script that calls `show()` at the end. The server continuously updates the document.
- deprecated The `gridplot` function is largely superseded by the more flexible `layout`, `row`, and `column` functions for arranging multiple plots or widgets.
Install
-
pip install bokeh
Imports
- figure
from bokeh.plotting import figure
- show
from bokeh.plotting import show
- ColumnDataSource
from bokeh.models import ColumnDataSource
- curdoc
from bokeh.io import curdoc
Quickstart
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
import numpy as np
x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
p = figure(width=600, height=400, title="Simple Sine Wave",
x_axis_label='x', y_axis_label='y')
p.line('x', 'y', source=source, line_width=2)
show(p)