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/two-scales.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/two-scales.rs')
-rw-r--r-- | vendor/plotters/examples/two-scales.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/plotters/examples/two-scales.rs b/vendor/plotters/examples/two-scales.rs new file mode 100644 index 000000000..6e1dfa4c2 --- /dev/null +++ b/vendor/plotters/examples/two-scales.rs @@ -0,0 +1,60 @@ +use plotters::prelude::*; + +const OUT_FILE_NAME: &'static str = "plotters-doc-data/twoscale.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) + .x_label_area_size(35) + .y_label_area_size(40) + .right_y_label_area_size(40) + .margin(5) + .caption("Dual Y-Axis Example", ("sans-serif", 50.0).into_font()) + .build_cartesian_2d(0f32..10f32, (0.1f32..1e10f32).log_scale())? + .set_secondary_coord(0f32..10f32, -1.0f32..1.0f32); + + chart + .configure_mesh() + .disable_x_mesh() + .disable_y_mesh() + .y_desc("Log Scale") + .y_label_formatter(&|x| format!("{:e}", x)) + .draw()?; + + chart + .configure_secondary_axes() + .y_desc("Linear Scale") + .draw()?; + + chart + .draw_series(LineSeries::new( + (0..=100).map(|x| (x as f32 / 10.0, (1.02f32).powf(x as f32 * x as f32 / 10.0))), + &BLUE, + ))? + .label("y = 1.02^x^2") + .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &BLUE)); + + chart + .draw_secondary_series(LineSeries::new( + (0..=100).map(|x| (x as f32 / 10.0, (x as f32 / 5.0).sin())), + &RED, + ))? + .label("y = sin(2x)") + .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED)); + + chart + .configure_series_labels() + .background_style(&RGBColor(128, 128, 128)) + .draw()?; + + // 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() +} |