Struct graplot::Plot

source ·
pub struct Plot {
    pub xs: Matrix,
    pub ys: Matrix,
    pub line_desc: Vec<LineDesc>,
    pub axis_desc: AxisDesc,
    pub desc: Desc,
}

Fields§

§xs: Matrix§ys: Matrix§line_desc: Vec<LineDesc>§axis_desc: AxisDesc§desc: Desc

Implementations§

Examples found in repository?
examples/1x.rs (line 4)
3
4
5
6
fn main() {
    let plot = Plot::new(|x| 1. / (x+4.));
    plot.show();
}
More examples
Hide additional examples
examples/ys.rs (line 4)
3
4
5
6
fn main() {
    let plot = Plot::new([-4., -2., 1., 4.]);
    plot.show();
}
examples/squared.rs (line 4)
3
4
5
6
fn main() {
    let plot = Plot::new(|x: f64| x.powf(2.));
    plot.show();
}
examples/tanh.rs (line 4)
3
4
5
6
fn main() {
    let plot = Plot::new((|x: f64| x.tanh(), x(6.)));
    plot.show()
}
examples/sigmoid.rs (line 4)
3
4
5
6
fn main() {
    let plot = Plot::new((|x: f64| 1. / (1. + (-x).exp()), x(6.)));
    plot.show()
}
examples/polynomial.rs (line 5)
3
4
5
6
7
fn main() {
    let poly = Polynomial::new(&[2., 3., 1.], &[2., 3., 2.]);
    let plot = Plot::new((poly, x(10.)));
    plot.show();
}
Examples found in repository?
examples/custom_scaling.rs (lines 5-9)
3
4
5
6
7
8
9
10
11
fn main() {
    let mut plot = Plot::new((|x: f64| x.cos(), x(5.)));
    plot.set_desc(Desc {
        min_steps_x: 6.,
        spacing_x: 47.,
        ..Default::default()
    });
    plot.show();
}
More examples
Hide additional examples
examples/collatz.rs (lines 6-10)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let mut plot = Plot::default();
    plot.set_title("Collatz Conjecture");
    plot.set_desc(Desc {
        min_steps_x: 10.,
        spacing_x: 47.,
        ..Default::default()
    });

    for input in 1000..=1001 {
        let mut single_graph = collatz(input as f64).as_plot();
        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
        plot.add(single_graph);
    }
    plot.show();
}

Set graph color

Example
use graplot::Plot;

let mut plot = Plot::new([1., 2., 3.]);
plot.set_color(0., 0.78, 1.);
plot.show();
Examples found in repository?
examples/collatz.rs (line 14)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let mut plot = Plot::default();
    plot.set_title("Collatz Conjecture");
    plot.set_desc(Desc {
        min_steps_x: 10.,
        spacing_x: 47.,
        ..Default::default()
    });

    for input in 1000..=1001 {
        let mut single_graph = collatz(input as f64).as_plot();
        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
        plot.add(single_graph);
    }
    plot.show();
}

Colors the graph at the given index with the color.

Example
use graplot::{Plot, BLUE};
 
let mut plot = Plot::new([1., 2., 3.,]);
plot.add([2., 3., 4.,]);
plot.color(1, BLUE);
plot.show();

adds a new graph / plot to the original plot.

Examples found in repository?
examples/multiple_plots.rs (line 12)
3
4
5
6
7
8
9
10
11
12
13
14
15
fn main() {
    let xs = [1., 2., 3.];
    let ys = [1.7, 3., 1.9];

    let ys1 = [1.4, 1.6, 1.5];

    let ys2 = [0.9, 1.2, 1.7, 1.9, 2.];

    let mut plot = Plot::new((xs, ys));
    plot.add((xs, ys1, "c-o"));
    plot.add((ys2, "r-"));
    plot.show();
}
More examples
Hide additional examples
examples/exp_fn.rs (line 6)
3
4
5
6
7
8
9
10
fn main() {
    let mut plot = Plot::new((|x: f64| (3f64).powf(x), x(3.)));
    let plot_2x = Plot::new((|x: f64| (2f64).powf(x), x(4.), "r"));
    plot.add(plot_2x);
    let plot_1_2x = Plot::new((|x: f64| (1./2f64).powf(x), x(4.), "b"));
    plot.add(plot_1_2x);
    plot.show();
}
examples/collatz.rs (line 15)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let mut plot = Plot::default();
    plot.set_title("Collatz Conjecture");
    plot.set_desc(Desc {
        min_steps_x: 10.,
        spacing_x: 47.,
        ..Default::default()
    });

    for input in 1000..=1001 {
        let mut single_graph = collatz(input as f64).as_plot();
        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
        plot.add(single_graph);
    }
    plot.show();
}
Examples found in repository?
examples/title_and_axis.rs (line 6)
3
4
5
6
7
8
9
10
fn main() {
    let mut plot = Plot::new((|x: f64| x.cos(), x(6.)));

    plot.set_title("cosine wave");
    plot.set_xlabel("x axis");
    plot.set_ylabel("y axis");
    plot.show();
}
More examples
Hide additional examples
examples/collatz.rs (line 5)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let mut plot = Plot::default();
    plot.set_title("Collatz Conjecture");
    plot.set_desc(Desc {
        min_steps_x: 10.,
        spacing_x: 47.,
        ..Default::default()
    });

    for input in 1000..=1001 {
        let mut single_graph = collatz(input as f64).as_plot();
        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
        plot.add(single_graph);
    }
    plot.show();
}
Examples found in repository?
examples/title_and_axis.rs (line 7)
3
4
5
6
7
8
9
10
fn main() {
    let mut plot = Plot::new((|x: f64| x.cos(), x(6.)));

    plot.set_title("cosine wave");
    plot.set_xlabel("x axis");
    plot.set_ylabel("y axis");
    plot.show();
}
Examples found in repository?
examples/title_and_axis.rs (line 8)
3
4
5
6
7
8
9
10
fn main() {
    let mut plot = Plot::new((|x: f64| x.cos(), x(6.)));

    plot.set_title("cosine wave");
    plot.set_xlabel("x axis");
    plot.set_ylabel("y axis");
    plot.show();
}
Examples found in repository?
examples/1x.rs (line 5)
3
4
5
6
fn main() {
    let plot = Plot::new(|x| 1. / (x+4.));
    plot.show();
}
More examples
Hide additional examples
examples/ys.rs (line 5)
3
4
5
6
fn main() {
    let plot = Plot::new([-4., -2., 1., 4.]);
    plot.show();
}
examples/squared.rs (line 5)
3
4
5
6
fn main() {
    let plot = Plot::new(|x: f64| x.powf(2.));
    plot.show();
}
examples/tanh.rs (line 5)
3
4
5
6
fn main() {
    let plot = Plot::new((|x: f64| x.tanh(), x(6.)));
    plot.show()
}
examples/sigmoid.rs (line 5)
3
4
5
6
fn main() {
    let plot = Plot::new((|x: f64| 1. / (1. + (-x).exp()), x(6.)));
    plot.show()
}
examples/polynomial.rs (line 6)
3
4
5
6
7
fn main() {
    let poly = Polynomial::new(&[2., 3., 1.], &[2., 3., 2.]);
    let plot = Plot::new((poly, x(10.)));
    plot.show();
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.