use plotters::prelude::*;
use plotters_statistical::stats::CorrelationMethod;
use plotters_statistical::CorrelationHeatmap;
fn noise(i: usize, salt: usize) -> f64 {
(((i * 31 + 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("correlation_heatmap.svg", (640, 560)).into_drawing_area();
root.fill(&WHITE)?;
let n = 200;
let mut age = Vec::new();
let mut income = Vec::new();
let mut spend = Vec::new();
let mut savings = Vec::new();
let mut random = Vec::new();
for i in 0..n {
let a = i as f64 / n as f64;
age.push(a + 0.1 * noise(i, 1));
income.push(2.0 * a + 0.3 * noise(i, 2)); spend.push(1.5 * a + 0.6 * noise(i, 3)); savings.push(-a + 0.4 * noise(i, 4)); random.push(noise(i, 5)); }
let columns = vec![age, income, spend, savings, random];
let labels = ["age", "income", "spend", "savings", "random"]
.iter()
.map(|s| s.to_string())
.collect();
CorrelationHeatmap::from_columns(&columns, labels, CorrelationMethod::Pearson)?
.title("Pearson correlation")
.precision(2)
.draw(&root)?;
root.present()?;
println!("wrote correlation_heatmap.svg");
Ok(())
}