Skillversitas

Specialized Curves

Beyond plain lines, Bokeh ships glyph methods for statistical and mathematical curves. Four of the most useful are step, quadratic/bezier, ray/segment, and reference span lines.

Step Lines

A step glyph holds each y-value flat until the next x. The mode parameter controls where the vertical jump happens — "after" (value holds until the next x), "before", or "center":

from bokeh.plotting import figure

p = figure(width=450, height=300)
p.step([1, 2, 3, 4, 5], [10, 8, 4, 6, 2],
       mode="after", line_width=2, color="navy", legend_label="after")
p.step([1, 2, 3, 4, 5], [10, 8, 4, 6, 2],
       mode="center", line_width=2, color="tomato",
       legend_label="center")

Quad and Bezier Segments

quadratic and bezier connect two points through control points, giving smooth connectors — useful in diagrams and flow charts. Each point carries both an endpoint and a control coordinate:

p.quadratic(x0=[1], y0=[2], x1=[5], y1=[6],
            cx=[4], cy=[0], line_width=2)
p.bezier(x0=[2], y0=[1], x1=[6], y1=[4],
         cx0=[3], cy0=[3], cx1=[5], cy1=[1],
         line_color="olive")

Segments and Rays

segment draws a finite line from (x0, y0) to (x1, y1) — ideal for error bars, slopes, and connectors. ray draws an infinite ray from a point along a given angle for a given length (in screen pixels by default):

p.segment(x0=[2], y0=[2], x1=[2], y1=[6],
          line_color="gray", line_dash="dashed")
p.ray(x=[2], y=[2], angle=0.7, length=120,
      line_color="firebrick", line_width=2)

A frequent pattern is drawing residuals as vertical segments between fitted and actual values:

p.segment(x0=xs, y0=fit, x1=xs, y1=actual,
          line_color="gray", alpha=0.6)

Spans

Span is an annotation rather than a glyph, but it draws reference lines that span the whole plot — a constant x or y value across the canvas:

from bokeh.models import Span

mean = sum([10, 8, 4, 6, 2]) / 5
v = Span(location=mean, dimension="width",
         line_color="red", line_dash="dashed")
p.add_layout(v)

Combining Curves with Shading

To emphasize a region, combine vbar/rect fills with curve glyphs, or use BoxAnnotation:

from bokeh.models import BoxAnnotation

band = BoxAnnotation(left=2, right=4,
                     fill_alpha=0.1, fill_color="green")
p.add_layout(band)

Summary

Specialized curve glyphs cover staircase series (step), smooth connectors (quadratic, bezier), infinite or finite straight lines (ray, segment), and full-canvas reference lines via the Span annotation — compose them with shading boxes to build analytic views.