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

Histogram

Bin a sample of scalar observations into equal-width buckets and emit one bar per bin. The default binning rule is the square-root rule (⌈√n⌉); pass BinCount::Fixed(n) for a fixed bin count.

The demo plots heights of Union Army recruits, c. 1864, drawn from Benjamin A. Gould's 1869 Investigations in the Military and Anthropological Statistics of American Soldiers — the largest systematic anthropometric study of the 19th century. The distribution centres on 67.8 in (~172 cm) with σ ≈ 2.5 in, the Gaussian fit Gould reported for the 25–34 age bracket, and later anchored Galton's work on regression to the mean.

Source: Anthropometric history — Wikipedia

Public surface

use wisp_chart::distributions::{BinCount, Histogram};

let samples: Vec<f32> = collect_observations();
let hist = Histogram::from_samples(
    &samples,
    BinCount::Auto,           // sqrt-rule
    Some((0.0, 100.0)),       // optional clamping extent
);
let g = hist.emit_graphics(&theme, Vec2::new(360.0, 240.0));

Binning rules

  • BinCount::Auto⌈√n⌉ bins. Cheap, robust, biased toward over-binning for very large samples.
  • BinCount::Fixed(k) — explicit bin count. Use when comparing multiple histograms side-by-side so the bars line up.

Histogram vs. KDE

A histogram shows you exactly which observations landed where — useful for outlier hunting and reading off exact counts. A KDE shows you the underlying density estimate — useful when the bin-edge choice would distort the story. They compose; some teams ship both stacked.