Skip to main content

multi_series/
multi_series.rs

1use ploot::prelude::*;
2
3fn main() {
4    let xs: Vec<f64> = (-30..=30).map(|i| i as f64 / 10.0).collect();
5    let quadratic: Vec<f64> = xs.iter().map(|&x| x * x).collect();
6    let cubic: Vec<f64> = xs.iter().map(|&x| x * x * x).collect();
7    let sine: Vec<f64> = xs.iter().map(|&x| 8.0 * (x * 1.5).sin()).collect();
8    let gaussian: Vec<f64> = xs.iter().map(|&x| 20.0 * (-x * x).exp()).collect();
9
10    let layout = Layout2D::new()
11        .with_title("x^2  vs  x^3  vs  8*sin(1.5x)  vs  20*e^(-x^2)")
12        .with_x_label("x")
13        .with_y_label("y")
14        .with_plot(LinePlot::new(xs.iter().copied(), quadratic.iter().copied()).with_caption("x^2"))
15        .with_plot(LinePlot::new(xs.iter().copied(), cubic.iter().copied()).with_caption("x^3"))
16        .with_plot(LinePlot::new(xs.iter().copied(), sine.iter().copied()).with_caption("8*sin(1.5x)"))
17        .with_plot(LinePlot::new(xs.iter().copied(), gaussian.iter().copied()).with_caption("20*e^(-x^2)"));
18
19    Figure::new()
20        .with_size(80, 24)
21        .with_layout(layout)
22        .show();
23}