1 use plotters::prelude::*;
2
3 use rand::SeedableRng;
4 use rand_distr::{Distribution, Normal};
5 use rand_xorshift::XorShiftRng;
6
main() -> Result<(), Box<dyn std::error::Error>>7 fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let data: Vec<_> = {
9 let norm_dist = Normal::new(500.0, 100.0).unwrap();
10 let mut x_rand = XorShiftRng::from_seed(*b"MyFragileSeed123");
11 let x_iter = norm_dist.sample_iter(&mut x_rand);
12 x_iter
13 .filter(|x| *x < 1500.0)
14 .take(100)
15 .zip(0..)
16 .map(|(x, b)| x + (b as f64).powf(1.2))
17 .collect()
18 };
19
20 let root =
21 BitMapBackend::new("plotters-doc-data/area-chart.png", (1024, 768)).into_drawing_area();
22
23 root.fill(&WHITE)?;
24
25 let mut chart = ChartBuilder::on(&root)
26 .set_label_area_size(LabelAreaPosition::Left, 60)
27 .set_label_area_size(LabelAreaPosition::Bottom, 60)
28 .caption("Area Chart Demo", ("sans-serif", 40))
29 .build_cartesian_2d(0..(data.len() - 1), 0.0..1500.0)?;
30
31 chart
32 .configure_mesh()
33 .disable_x_mesh()
34 .disable_y_mesh()
35 .draw()?;
36
37 chart.draw_series(
38 AreaSeries::new(
39 (0..).zip(data.iter()).map(|(x, y)| (x, *y)),
40 0.0,
41 &RED.mix(0.2),
42 )
43 .border_style(&RED),
44 )?;
45
46 Ok(())
47 }
48 #[test]
entry_point()49 fn entry_point() {
50 main().unwrap()
51 }
52