Skillversitas

Basic Concepts

Every Bokeh visualization is a graph of serializable Python objects called models. Understanding five of them — Figure, Glyph, DataSource, Renderer, and Layout — explains almost everything you will read in Bokeh code.

Figure and Glyphs

A figure is the plotting canvas with axes, grids, and tools attached. Glyphs are the marks drawn on it: circles, lines, wedges, rectangles, text. Each glyph is a collection of value properties (screen distances like radius or size), data properties bound to column names, and visual attribute groups such as fill_color and line_alpha.

from bokeh.plotting import figure

p = figure(width=350, height=250)
p.circle(x=[1, 2, 3], y=[4, 5, 6], size=12, fill_color="teal", alpha=0.7)

Data Sources

By default Bokeh wraps literal sequences into a ColumnDataSource for you. A ColumnDataSource is a column-oriented dictionary — every column must be the same length — and it is the object the Bokeh Server updates so a browser re-renders without resending the plot.

from bokeh.models import ColumnDataSource

source = ColumnDataSource(data=dict(
    temp=[31, 30, 27, 29],
    humidity=[52, 51, 55, 54],
))
p.circle(x="temp", y="humidity", source=source, size=10)
# update later in place:
source.data = dict(temp=[33, 31, 28], humidity=[50, 53, 55])

Renderers and Properties

Calling p.circle() neither draws immediately nor returns a color — it returns a glyph_renderer model added to p.renderers. Visual attributes resolve through a layered property system: glyph defaults, then renderer overrides, then figure-level theme. This is why you can change styling after the fact:

r = p.line(x=[1, 2, 3], y=[2, 4, 6])
r.glyph.line_dash = "dashed"
r.glyph.line_width = 3

Vectorized Attributes

Any visual property may take a per-point column instead of a scalar. Sizes, colors, and alphas can all be data-driven, and property mappings such as factormap or LinearColorMapper turn categories or numbers into palettes:

from bokeh.transform import linear_cmap
from bokeh.palettes import Viridis256

p.circle(x="x", y="y", source=source, size=9,
         color=linear_cmap("temp", Viridis256, 25, 35))

Relationships in a Diagram

The object graph flows like this:

  • Document — root container holding everything
  • Layout — row, column, or gridplot arranging figures
  • Figure — canvas with renderers, axes, tools
  • Renderer — binds one Glyph to one DataSource
  • Glyph — shape plus resolved visual properties

Naming Things

Models accept a name, and figures can hold tags. Assigning names lets other code find models again, which is essential in Bokeh Server apps and CustomJS callbacks:

s = ColumnDataSource(data=dict(x=[1], y=[1]), name="marker_source")

Summary

Bokeh plots are trees of models: a figure arranges renderers, each renderer couples a glyph to a column-oriented data source, and property vectors or mappers let any visual attribute vary per point — with names assigned so callbacks can find them later.