Struct 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§

Source§

impl Plot

Source

pub fn new(args: impl PlotArg) -> Plot

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

pub fn set_desc(&mut self, desc: Desc)

Examples found in repository?
examples/custom_scaling.rs (lines 5-9)
3fn main() {
4    let mut plot = Plot::new((|x: f64| x.cos(), x(5.)));
5    plot.set_desc(Desc {
6        min_steps_x: 6.,
7        spacing_x: 47.,
8        ..Default::default()
9    });
10    plot.show();
11}
More examples
Hide additional examples
examples/collatz.rs (lines 6-10)
3fn main() {
4    let mut plot = Plot::default();
5    plot.set_title("Collatz Conjecture");
6    plot.set_desc(Desc {
7        min_steps_x: 10.,
8        spacing_x: 47.,
9        ..Default::default()
10    });
11
12    for input in 1000..=1001 {
13        let mut single_graph = collatz(input as f64).as_plot();
14        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
15        plot.add(single_graph);
16    }
17    plot.show();
18}
Source

pub fn set_color(&mut self, r: f32, g: f32, b: f32)

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)
3fn main() {
4    let mut plot = Plot::default();
5    plot.set_title("Collatz Conjecture");
6    plot.set_desc(Desc {
7        min_steps_x: 10.,
8        spacing_x: 47.,
9        ..Default::default()
10    });
11
12    for input in 1000..=1001 {
13        let mut single_graph = collatz(input as f64).as_plot();
14        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
15        plot.add(single_graph);
16    }
17    plot.show();
18}
Source

pub fn color(&mut self, idx: usize, color: Color)

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();
Source

pub fn add<A: PlotArg>(&mut self, args: A)

adds a new graph / plot to the original plot.

Examples found in repository?
examples/multiple_plots.rs (line 12)
3fn main() {
4    let xs = [1., 2., 3.];
5    let ys = [1.7, 3., 1.9];
6
7    let ys1 = [1.4, 1.6, 1.5];
8
9    let ys2 = [0.9, 1.2, 1.7, 1.9, 2.];
10
11    let mut plot = Plot::new((xs, ys));
12    plot.add((xs, ys1, "c-o"));
13    plot.add((ys2, "r-"));
14    plot.show();
15}
More examples
Hide additional examples
examples/exp_fn.rs (line 6)
3fn main() {
4    let mut plot = Plot::new((|x: f64| (3f64).powf(x), x(3.)));
5    let plot_2x = Plot::new((|x: f64| (2f64).powf(x), x(4.), "r"));
6    plot.add(plot_2x);
7    let plot_1_2x = Plot::new((|x: f64| (1./2f64).powf(x), x(4.), "b"));
8    plot.add(plot_1_2x);
9    plot.show();
10}
examples/collatz.rs (line 15)
3fn main() {
4    let mut plot = Plot::default();
5    plot.set_title("Collatz Conjecture");
6    plot.set_desc(Desc {
7        min_steps_x: 10.,
8        spacing_x: 47.,
9        ..Default::default()
10    });
11
12    for input in 1000..=1001 {
13        let mut single_graph = collatz(input as f64).as_plot();
14        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
15        plot.add(single_graph);
16    }
17    plot.show();
18}
Source

pub fn set_title(&mut self, title: &str)

Examples found in repository?
examples/title_and_axis.rs (line 6)
3fn main() {
4    let mut plot = Plot::new((|x: f64| x.cos(), x(6.)));
5
6    plot.set_title("cosine wave");
7    plot.set_xlabel("x axis");
8    plot.set_ylabel("y axis");
9    plot.show();
10}
More examples
Hide additional examples
examples/collatz.rs (line 5)
3fn main() {
4    let mut plot = Plot::default();
5    plot.set_title("Collatz Conjecture");
6    plot.set_desc(Desc {
7        min_steps_x: 10.,
8        spacing_x: 47.,
9        ..Default::default()
10    });
11
12    for input in 1000..=1001 {
13        let mut single_graph = collatz(input as f64).as_plot();
14        single_graph.set_color(0., 1. * (input == 1000) as i32 as f32, 1.);
15        plot.add(single_graph);
16    }
17    plot.show();
18}
Source

pub fn set_xlabel(&mut self, label: &str)

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

pub fn set_ylabel(&mut self, label: &str)

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

pub fn show(self)

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

Trait Implementations§

Source§

impl Clone for Plot

Source§

fn clone(&self) -> Plot

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Plot

Source§

fn default() -> Plot

Returns the “default value” for a type. Read more
Source§

impl PlotArg for Plot

Source§

fn as_plot(&self) -> Plot

Auto Trait Implementations§

§

impl Freeze for Plot

§

impl RefUnwindSafe for Plot

§

impl Send for Plot

§

impl Sync for Plot

§

impl Unpin for Plot

§

impl UnwindSafe for Plot

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.