plotters_statistical/lib.rs
1//! # plotters-statistical
2//!
3//! Statistical chart primitives for [`plotters`](https://docs.rs/plotters),
4//! packaged as reusable *series types* that plug into
5//! [`ChartContext::draw_series`](plotters::chart::ChartContext::draw_series)
6//! exactly like `plotters`' own built-in `Histogram` / `LineSeries` /
7//! `CandleStick`.
8//!
9//! Every chart type in this crate is a composite element that follows the same
10//! [`Drawable`](plotters::element::Drawable) +
11//! [`PointCollection`](plotters::element::PointCollection) pattern `plotters`
12//! uses internally (its `CandleStick` element is the closest analogue), so they
13//! feel native rather than bolted on.
14//!
15//! ## Chart types
16//!
17//! | Type | Replaces (matplotlib / seaborn) |
18//! |------|---------------------------------|
19//! | [`BoxPlot`] / [`BoxPlotSeries`] | `matplotlib.boxplot`, `seaborn.boxplot` |
20//! | [`ViolinPlot`] / [`ViolinPlotSeries`] | `seaborn.violinplot` |
21//! | [`RocCurve`] | `sklearn.metrics.RocCurveDisplay` |
22//! | [`PrecisionRecallCurve`] | `sklearn.metrics.PrecisionRecallDisplay` |
23//! | [`RegularizationPath`] | `sklearn` coefficient-path plots |
24//! | [`ResidualPlot`] | `seaborn.residplot` |
25//!
26//! ## Design: math is separate from rendering
27//!
28//! All numeric work lives in [`stats`] and has no `plotters` dependency, so it
29//! can be unit-tested against hand-computed values. The [`series`] types only
30//! turn already-computed geometry into `plotters` draw calls.
31//!
32//! ## Quick start
33//!
34//! ```no_run
35//! use plotters::prelude::*;
36//! use plotters_statistical::BoxPlotSeries;
37//!
38//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
39//! let root = SVGBackend::new("boxes.svg", (640, 480)).into_drawing_area();
40//! root.fill(&WHITE)?;
41//! let mut chart = ChartBuilder::on(&root)
42//! .margin(20)
43//! .set_label_area_size(LabelAreaPosition::Left, 40)
44//! .set_label_area_size(LabelAreaPosition::Bottom, 40)
45//! .build_cartesian_2d(0f64..3f64, 0f64..10f64)?;
46//! chart.configure_mesh().draw()?;
47//!
48//! let groups = vec![
49//! (1.0, vec![1.0, 2.0, 2.5, 3.0, 9.0]),
50//! (2.0, vec![2.0, 3.0, 3.5, 4.0, 4.2]),
51//! ];
52//! chart.draw_series(BoxPlotSeries::from_samples(groups)?)?;
53//! root.present()?;
54//! # Ok(())
55//! # }
56//! ```
57#![warn(missing_docs)]
58
59pub mod colormap;
60pub mod figures;
61pub mod stats;
62pub mod style;
63
64pub mod series;
65
66#[doc(inline)]
67pub use series::{
68 BoxPlot, BoxPlotSeries, BoxStyle, CalibrationCurve, Ecdf, GainChart, Heatmap,
69 PrecisionRecallCurve, QqPlot, RegLine, RegularizationPath, ResidualPlot, RocCurve, ViolinPlot,
70 ViolinPlotSeries, ViolinStyle,
71};
72
73#[doc(inline)]
74pub use colormap::{GradientColorMap, Normalization};
75
76#[doc(inline)]
77pub use figures::{CorrelationHeatmap, MissingnessHeatmap, PairPlot};
78
79#[doc(inline)]
80pub use stats::StatsError;