Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Connected scatterplot

A scatterplot whose points are joined by a line in a meaningful sequence — usually time. The reader sees the trajectory through 2D space, not just where points cluster.

The demo plots the US Phillips curve, 1960 → 1980, with annual (inflation, unemployment) pairs joined in chronological order. The 1960s sit in the lower-left in the classic downward trade-off; the 1970s stagflation shock punches the line out toward the upper-right (both axes climbing together) — the empirical observation that broke Keynesian consensus and powered Milton Friedman's natural-rate theory.

Source: Phillips curve — Wikipedia

Public surface

let plot = Plot::new(quarterly)
    .mark(Mark::Line {
        interpolation: Interpolation::Linear,
        marker: Some(PointStyle::Circle),
    })
    .encode(plot::x("inflation", ScaleKind::Linear))
    .encode(plot::y("unemployment", ScaleKind::Linear))
    .encode(plot::order("quarter_index"))
    .encode(plot::color("decade"));

The minimum recipe: a line mark with markers on, X and Y both Linear, and an order encoding that names the sort column.

Order encoding

Info

Encoding::Order sorts each series's rows by the named numeric column before line-segment emission. Without it, rows are connected in DataFrame insertion order — fine for already- sorted time series, wrong for shuffled input. Always set it when your reader expects the line to follow time.

Continuous-X line vs band-X line

The Plot facade detects the X scale kind and routes:

X ScaleKindLayoutUse case
Linear / Log / TimeContinuous numeric axesConnected scatter, time-series
Band (default)Categorical bands at centresStandard line chart, e.g. quarterly

Same Mark::Line mark; different X scale picks the right projection automatically.