Data Lifetime

ezel retains user data in memory until the object is dropped.

for _ in 0..1000 {
    plot.scatter(random_million_points());
}
// plot has 1_000*1_000_000 points in memory

// layout and axis limits are determined from 1_000*1_000_000 points
plot.draw_to_file("large.png", (500, 500)).unwrap();

Sometimes it is desirable to save the memory by dumping the data onto the bitmap target and dropping the data immediately. ezel does not support this yet, meanwhile you can use plotters library at the cost of manual specification of layouts and limits.

// Plotters example
use plotters::prelude::*;

let mut cc = ChartBuilder::on(&upper)
    .margin(5)
    .set_all_label_area_size(50)  // you should manually calculate this
    .caption("Sine and Cosine", ("sans-serif", 40))
    .build_cartesian_2d(-3.4f32..3.4, -1.2f32..1.2f32)?;

cc.configure_mesh()
    .x_labels(20)  // you should manually calculate this
    .y_labels(10)  // you should manually calculate this
    .disable_mesh()
    .x_label_formatter(&|v| format!("{:.1}", v))
    .y_label_formatter(&|v| format!("{:.1}", v))
    .draw()?;

Last updated