Skip to main content

Crate plotters_statistical

Crate plotters_statistical 

Source
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

TypeReplaces (matplotlib / seaborn)
BoxPlot / BoxPlotSeriesmatplotlib.boxplot, seaborn.boxplot
ViolinPlot / ViolinPlotSeriesseaborn.violinplot
RocCurvesklearn.metrics.RocCurveDisplay
PrecisionRecallCurvesklearn.metrics.PrecisionRecallDisplay
RegularizationPathsklearn coefficient-path plots
ResidualPlotseaborn.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 single draw_series call.
series
plotters-facing series types.
stats
Pure statistical computation — no plotters dependency.
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.
BoxPlotSeries
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).
CalibrationCurve
A reliability diagram as a drawable series (coordinate space (f64, f64) = (mean predicted probability, observed frequency)).
CorrelationHeatmap
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)).
GainChart
A cumulative gain or lift chart as a drawable series (coordinate space (f64, f64)).
GradientColorMap
A color map built from sorted RGB stops, interpolated linearly in RGB space.
Heatmap
A grid of color-mapped cells.
MissingnessHeatmap
A present/absent map: one column per variable, observations down the rows.
PairPlot
A scatterplot matrix.
PrecisionRecallCurve
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.
RegularizationPath
A full regularization path — one RegLine per coefficient.
ResidualPlot
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)).
ViolinPlot
A single violin at one coordinate on the category axis.
ViolinPlotSeries
A group of violins laid out side by side — mirrors BoxPlotSeries.
ViolinStyle
Styling for a violin plot.

Enums§

Normalization
Maps a data value onto the [0, 1] input of a GradientColorMap.
StatsError
Errors returned by the statistics routines for inputs where a metric is undefined, rather than letting NaN propagate silently into a chart.