Expand description
§plotters-statistical
Statistical chart primitives for plotters,
packaged as reusable series types that plug into
ChartContext::draw_series
exactly like plotters’ own built-in Histogram / LineSeries /
CandleStick.
Every chart type in this crate is a composite element that follows the same
Drawable +
PointCollection pattern plotters
uses internally (its CandleStick element is the closest analogue), so they
feel native rather than bolted on.
§Chart types
| Type | Replaces (matplotlib / seaborn) |
|---|---|
BoxPlot / BoxPlotSeries | matplotlib.boxplot, seaborn.boxplot |
ViolinPlot / ViolinPlotSeries | seaborn.violinplot |
RocCurve | sklearn.metrics.RocCurveDisplay |
PrecisionRecallCurve | sklearn.metrics.PrecisionRecallDisplay |
RegularizationPath | sklearn coefficient-path plots |
ResidualPlot | seaborn.residplot |
§Design: math is separate from rendering
All numeric work lives in stats and has no plotters dependency, so it
can be unit-tested against hand-computed values. The series types only
turn already-computed geometry into plotters draw calls.
§Quick start
use plotters::prelude::*;
use plotters_statistical::BoxPlotSeries;
let root = SVGBackend::new("boxes.svg", (640, 480)).into_drawing_area();
root.fill(&WHITE)?;
let mut chart = ChartBuilder::on(&root)
.margin(20)
.set_label_area_size(LabelAreaPosition::Left, 40)
.set_label_area_size(LabelAreaPosition::Bottom, 40)
.build_cartesian_2d(0f64..3f64, 0f64..10f64)?;
chart.configure_mesh().draw()?;
let groups = vec![
(1.0, vec![1.0, 2.0, 2.5, 3.0, 9.0]),
(2.0, vec![2.0, 3.0, 3.5, 4.0, 4.2]),
];
chart.draw_series(BoxPlotSeries::from_samples(groups)?)?;
root.present()?;Modules§
- colormap
- Continuous color maps and value normalization for heatmaps and any other value-to-color chart.
- figures
- Figure-level builders: charts that own their own axes / multi-panel layout
and render onto a whole
DrawingArea, rather than plugging into a singledraw_seriescall. - series
plotters-facing series types.- stats
- Pure statistical computation — no
plottersdependency. - style
- Shared styling: a color-blind-safe default palette and small helpers for
building
ShapeStyles, used by every chart type so the crate’s output is visually consistent.
Structs§
- BoxPlot
- A single box-and-whisker, positioned at one coordinate on the category axis.
- BoxPlot
Series - A group of boxes laid out side by side — one per named sample — since real use cases (one box per class/feature) always need several boxes on one chart, not a single isolated box.
- BoxStyle
- Visual styling for a box plot. Every field is overridable; the defaults are
a shared starting point (see
crate::style). - Calibration
Curve - A reliability diagram as a drawable series (coordinate space
(f64, f64)=(mean predicted probability, observed frequency)). - Correlation
Heatmap - A correlation heatmap: a square, labeled, color-mapped grid of a correlation matrix, with an optional colorbar and per-cell value annotations.
- Ecdf
- An empirical cumulative distribution function as a drawable step series
(coordinate space
(f64, f64)=(value, cumulative proportion)). - Gain
Chart - A cumulative gain or lift chart as a drawable series (coordinate space
(f64, f64)). - Gradient
Color Map - A color map built from sorted RGB stops, interpolated linearly in RGB space.
- Heatmap
- A grid of color-mapped cells.
- Missingness
Heatmap - A present/absent map: one column per variable, observations down the rows.
- Pair
Plot - A scatterplot matrix.
- Precision
Recall Curve - A single precision–recall curve as a drawable series (coordinate space
(f64, f64)=(recall, precision)). - QqPlot
- A normal Q–Q plot as a drawable series (coordinate space
(f64, f64)=(theoretical quantile, sample quantile)). - RegLine
- One coefficient’s trajectory across the strength axis.
- Regularization
Path - A full regularization path — one
RegLineper coefficient. - Residual
Plot - A residual plot as a drawable series (coordinate space
(f64, f64)=(fitted, residual)). - RocCurve
- A single ROC curve as a drawable series (coordinate space
(f64, f64)=(FPR, TPR)). - Violin
Plot - A single violin at one coordinate on the category axis.
- Violin
Plot Series - A group of violins laid out side by side — mirrors
BoxPlotSeries. - Violin
Style - Styling for a violin plot.
Enums§
- Normalization
- Maps a data value onto the
[0, 1]input of aGradientColorMap. - Stats
Error - Errors returned by the statistics routines for inputs where a metric is
undefined, rather than letting
NaNpropagate silently into a chart.