dataplotlib::util

Function zip2

Source
pub fn zip2<T>(a: &Vec<T>, b: &Vec<T>) -> Vec<(T, T)>
where T: Copy,
Expand description

zip2 will combine two Vec<T> into a single Vec<(T, T)> with a length equal to the length of the shorter input Vec. Rust has a built in zip function, but it has a signature that yields Vec<(&T, &T)> which is undesirable.

Examples found in repository?
examples/simplexy.rs (line 10)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
        let x = linspace(0, 10, 100);
    
    let y_sin = x.iter().map(|x| x.sin()).collect();
    let xy_sin = zip2(&x, &y_sin);

    let xy_lin = zip2(&x, &x);

    // Creates a new plot builder
    let mut pb = PlotBuilder2D::new();
    
    // Adds the sin plot and the cos plot
    pb.add_simple_xy(xy_sin);
    pb.add_simple_xy(xy_lin);

    let mut plt = Plotter::new();
    plt.plot2d(pb);
    plt.join();
}
More examples
Hide additional examples
examples/coloredxy.rs (line 10)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let x = linspace(0, 10, 100);
    
    let y_sin = x.iter().map(|x| x.sin()).collect();
    let xy_sin = zip2(&x, &y_sin);

    let xy_lin = zip2(&x, &x);

    // Creates a new plot builder
    let mut pb = PlotBuilder2D::new();
    
    // Adds the sin plot and the linear plot with custom colors
    pb.add_color_xy(xy_sin, [1.0, 0.0, 0.0, 1.0]);
    pb.add_color_xy(xy_lin, [0.0, 0.0, 1.0, 1.0]);
    
    let mut plt = Plotter::new();
    plt.plot2d(pb);
    plt.join();
}