diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/plotters/examples/matshow.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/plotters/examples/matshow.rs')
-rw-r--r-- | vendor/plotters/examples/matshow.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/plotters/examples/matshow.rs b/vendor/plotters/examples/matshow.rs new file mode 100644 index 000000000..30c71a745 --- /dev/null +++ b/vendor/plotters/examples/matshow.rs @@ -0,0 +1,62 @@ +use plotters::prelude::*; + +const OUT_FILE_NAME: &'static str = "plotters-doc-data/matshow.png"; +fn main() -> Result<(), Box<dyn std::error::Error>> { + let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area(); + + root.fill(&WHITE)?; + + let mut chart = ChartBuilder::on(&root) + .caption("Matshow Example", ("sans-serif", 80)) + .margin(5) + .top_x_label_area_size(40) + .y_label_area_size(40) + .build_cartesian_2d(0i32..15i32, 15i32..0i32)?; + + chart + .configure_mesh() + .x_labels(15) + .y_labels(15) + .max_light_lines(4) + .x_label_offset(35) + .y_label_offset(25) + .disable_x_mesh() + .disable_y_mesh() + .label_style(("sans-serif", 20)) + .draw()?; + + let mut matrix = [[0; 15]; 15]; + + for i in 0..15 { + matrix[i][i] = i + 4; + } + + chart.draw_series( + matrix + .iter() + .zip(0..) + .map(|(l, y)| l.iter().zip(0..).map(move |(v, x)| (x as i32, y as i32, v))) + .flatten() + .map(|(x, y, v)| { + Rectangle::new( + [(x, y), (x + 1, y + 1)], + HSLColor( + 240.0 / 360.0 - 240.0 / 360.0 * (*v as f64 / 20.0), + 0.7, + 0.1 + 0.4 * *v as f64 / 20.0, + ) + .filled(), + ) + }), + )?; + + // To avoid the IO failure being ignored silently, we manually call the present function + root.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir"); + println!("Result has been saved to {}", OUT_FILE_NAME); + + Ok(()) +} +#[test] +fn entry_point() { + main().unwrap() +} |