use plotters::prelude::*;
use plotters_statistical::MissingnessHeatmap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = SVGBackend::new("missingness_heatmap.svg", (720, 520)).into_drawing_area();
root.fill(&WHITE)?;
let n = 300;
let mut columns: Vec<Vec<Option<f64>>> = Vec::new();
columns.push((0..n).map(|i| Some(i as f64)).collect());
columns.push(
(0..n)
.map(|i| if i % 20 == 7 { None } else { Some(30.0) })
.collect(),
);
columns.push(
(0..n)
.map(|i| if i < n / 3 { None } else { Some(50.0) })
.collect(),
);
columns.push(
(0..n)
.map(|i| if i % 5 < 2 { None } else { Some(0.5) })
.collect(),
);
columns.push((0..n).map(|_| Some(1.0)).collect());
columns.push(
(0..n)
.map(|i| if i % 10 == 0 { Some(1.0) } else { None })
.collect(),
);
let labels = ["id", "age", "income", "score", "region", "note"]
.iter()
.map(|s| s.to_string())
.collect();
MissingnessHeatmap::from_columns(&columns, labels)?
.title("Missing data by column")
.draw(&root)?;
root.present()?;
println!("wrote missingness_heatmap.svg");
Ok(())
}