plotters-statistical 0.1.0

Statistical chart primitives (box, violin, ROC, PR, regularization-path, residual) as native plotters series
Documentation
//! Multi-group vertical box plot rendered to `box_plot.svg`.
//!
//! Also demonstrates overriding the default style (Milestone 7): the box fill
//! is switched to a custom color.

use plotters::prelude::*;
use plotters_statistical::style::{fill_style, palette_color};
use plotters_statistical::{BoxPlotSeries, BoxStyle};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = SVGBackend::new("box_plot.svg", (800, 500)).into_drawing_area();
    root.fill(&WHITE)?;

    // Three groups; the third carries a high outlier to exercise the marker.
    let groups = vec![
        (1.0f64, vec![4.0, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0]),
        (2.0f64, vec![2.0, 3.0, 3.2, 3.5, 4.0, 4.5, 5.0, 5.2]),
        (3.0f64, vec![5.0, 6.0, 6.5, 7.0, 7.5, 8.0, 9.0, 18.0]),
    ];

    let mut chart = ChartBuilder::on(&root)
        .caption("Box plot (3 groups)", ("sans-serif", 24))
        .margin(20)
        .set_label_area_size(LabelAreaPosition::Left, 45)
        .set_label_area_size(LabelAreaPosition::Bottom, 45)
        .build_cartesian_2d(0.5f64..3.5f64, 0f64..20f64)?;

    chart
        .configure_mesh()
        .x_desc("group")
        .y_desc("value")
        .draw()?;

    // Style override: custom translucent fill in the crate's palette.
    let style = BoxStyle {
        box_fill: fill_style(&palette_color(3).mix(0.4)),
        ..BoxStyle::default()
    };

    chart.draw_series(BoxPlotSeries::from_samples(groups)?.width(48).style(style))?;

    root.present()?;
    println!("wrote box_plot.svg");
    Ok(())
}