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

Density (KDE)

Kernel-density estimate over a 1D sample. Smooths the discrete histogram into a continuous density curve. Defaults to a Gaussian kernel + Silverman's rule of thumb for the bandwidth.

The demo uses the same dataset as the histogram chapter — heights of Union Army recruits, c. 1864 (Gould's 1869 Statistics of American Soldiers). The smoothed density makes it obvious that the binned heights are essentially Gaussian around 67.8 in; the bandwidth choice controls how aggressively adjacent bins blur into one another.

Source: Anthropometric history — Wikipedia

Public surface

use wisp_chart::distributions::{BandwidthRule, KdePlot};

let kde = KdePlot::new(samples)
    .bandwidth(BandwidthRule::Silverman);    // or Manual(0.5)
let g = kde.emit_graphics(&theme, Vec2::new(360.0, 240.0));

Bandwidth rules

  • BandwidthRule::Silverman1.06·σ·n^(-1/5). Robust default for unimodal data. Mildly over-smooths bimodal distributions.
  • BandwidthRule::Manual(h) — pick your own. Useful for reproducing a published figure with a known bandwidth.

Faceted density

Render one KDE per category by repeating this fixture inside the trellis / small-multiples layout. Same value type, different containing layout — the faceted-density chapter walks through it.