plotters-statistical 0.1.0

Statistical chart primitives (box, violin, ROC, PR, regularization-path, residual) as native plotters series
Documentation
//! Pair plot (scatterplot matrix) rendered to `pair_plot.svg`, colored by class.

use plotters::prelude::*;
use plotters_statistical::figures::Diagonal;
use plotters_statistical::PairPlot;

fn noise(i: usize, salt: usize) -> f64 {
    (((i * 17 + salt) as f64 * 12.9898).sin() * 43758.5453).rem_euclid(1.0) - 0.5
}

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

    // Two clusters in 3 features (a toy iris-like set).
    let n = 120;
    let mut f1 = Vec::new();
    let mut f2 = Vec::new();
    let mut f3 = Vec::new();
    let mut group = Vec::new();
    for i in 0..n {
        let cls = i % 2;
        let center = if cls == 0 { 0.0 } else { 3.0 };
        f1.push(center + noise(i, 1));
        f2.push(center * 0.5 + noise(i, 2));
        f3.push(2.0 - center + noise(i, 3));
        group.push(cls);
    }

    let columns = vec![f1, f2, f3];
    let labels = ["f1", "f2", "f3"].iter().map(|s| s.to_string()).collect();

    PairPlot::new(columns, labels)
        .diagonal(Diagonal::Histogram)
        .hue(group)
        .marker_radius(2)
        .draw(&root)?;

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