Skillversitas

Plots with Glyphs

Glyphs are the vocabulary of Bokeh plots. A glyph call binds shape geometry to data coordinates and produces a renderer on the figure. This chapter walks through the most common glyph categories and how their parameters map to visuals.

Marker Glyphs

Markers are point-like shapes centered on data coordinates: circle, square, triangle, diamond, cross, x, and asterisk variants. Their size is in screen units:

from bokeh.plotting import figure

p = figure(width=450, height=300)
p.circle([1, 2, 3], [3, 6, 9], size=12)
p.square([1, 2, 3], [1, 2, 3], size=12, color="orange")
p.triangle([1, 2, 3], [5, 7, 11], size=12, color="green")

Line Glyphs

The line glyph joins points in the order they appear in the data, so sort before plotting a series:

xs = sorted([5, 1, 3, 2, 4])
ys = [x * 2 + 1 for x in xs]
p.line(xs, ys, line_width=3, line_cap="round")

For stepped data, step renders right-angle segments with a mode of "after", "before", or "center":

p.step([1, 2, 3, 4], [1, 4, 2, 8], line_width=2, mode="after")

Patch and Area Glyphs

patch fills the polygon whose single sequence of points you give, and patches draws many at once:

p.patch([1, 2, 3, 4], [1, 4, 3, 1], alpha=0.4, color="olive",
        line_width=2)

varea and harea fill between two series, which makes them the basis of area charts:

p.varea(x=[1, 2, 3, 4], y1=[1, 2, 3, 4], y2=[3, 5, 4, 6], alpha=0.3)

Bar Glyphs

vbar and hbar accept width or height in data units and are the standard bar-chart glyphs:

fruits = ["apples", "pears", "melons"]
counts = [12, 25, 9]
p.vbar(x=fruits, top=counts, bottom=0, width=0.6)

Rect, Ellipse and Text

rect takes width and height per point, ellipse takes angle-bearing extents, and text places strings at points:

p.rect(x=[2], y=[5], width=[1], height=[2],
       angle=0.3, fill_color="steelblue", alpha=0.4)
p.text(x=[2], y=[8], text=["note"], text_align="center")

Image Glyphs

For rasterized data, image accepts a 2-D array plus left/bottom anchors and per-image width/height in data units, and image_url places pictures from the web:

Summary

Bokeh glyph calls share one contract — positions in data space, sizes in screen or data space, visual properties scalar or vectorized — and the marker, line, patch, bar, rect, and image families cover most chart types.