1use plotters::prelude::*;
2const OUT_FILE_NAME: &'static str = "plotters-doc-data/nested_coord.png";
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let root = BitMapBackend::new(OUT_FILE_NAME, (640, 480)).into_drawing_area();
5
6 root.fill(&WHITE)?;
7
8 let mut chart = ChartBuilder::on(&root)
9 .x_label_area_size(35)
10 .y_label_area_size(40)
11 .margin(5)
12 .caption("Nested Coord", ("sans-serif", 50.0))
13 .build_cartesian_2d(
14 ["Linear", "Quadratic"].nested_coord(|_| 0.0..10.0),
15 0.0..10.0,
16 )?;
17
18 chart
19 .configure_mesh()
20 .disable_mesh()
21 .axis_desc_style(("sans-serif", 15))
22 .draw()?;
23
24 chart.draw_series(LineSeries::new(
25 (0..10)
26 .map(|x| x as f64 / 1.0)
27 .map(|x| ((&"Linear", x).into(), x)),
28 &RED,
29 ))?;
30
31 chart.draw_series(LineSeries::new(
32 (0..10)
33 .map(|x| x as f64 / 1.0)
34 .map(|x| ((&"Quadratic", x).into(), x * x / 10.0)),
35 &RED,
36 ))?;
37
38 // To avoid the IO failure being ignored silently, we manually call the present function
39 root.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir");
40 println!("Result has been saved to {}", OUT_FILE_NAME);
41
42 Ok(())
43}
44#[test]
45fn entry_point() {
46 main().unwrap()
47}
48