plotlib::view

Struct CategoricalView

Source
pub struct CategoricalView { /* private fields */ }
Expand description

A view with categorical entries along the x-axis and continuous values along the y-axis

Implementations§

Source§

impl CategoricalView

Source

pub fn new() -> CategoricalView

Create an empty view

Examples found in repository?
examples/barchart_svg.rs (line 12)
6
7
8
9
10
11
12
13
14
15
fn main() {
    let b1 = BarChart::new(5.3).label("1");
    let b2 = BarChart::new(2.6)
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");

    Page::single(&v).save("barchart.svg").expect("saving svg");
}
More examples
Hide additional examples
examples/with_grid.rs (line 33)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn render_barchart<S>(filename: S)
where
    S: AsRef<str>,
{
    let b1 = BarChart::new(5.3).label("1");
    let b2 = BarChart::new(2.6)
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));
    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
    v.add_grid(Grid::new(3, 8));
    Page::single(&v)
        .save(filename.as_ref())
        .expect("saving svg");
}
examples/boxplot_svg.rs (line 12)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let b1 = BoxPlot::from_slice(&[1.0, 4.0, 2.0, 3.5, 6.4, 2.5, 7.5, 1.8, 9.6]).label("1");
    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new()
        .add(b1)
        .add(b2)
        .x_label("Experiment")
        .y_label("y");

    Page::single(&v)
        .dimensions(400, 300)
        .save("boxplot.svg")
        .expect("saving svg");
}
examples/letter_counter.rs (line 23)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let mut data = Vec::new();
    let message: &str = "This is a long message";
    let mut count = BTreeMap::new();

    for c in message.trim().to_lowercase().chars() {
        if c.is_alphabetic() {
            *count.entry(c).or_insert(0) += 1
        }
    }

    println!("Number of occurences per character");
    for (ch, count) in &count {
        println!("{:?}: {}", ch, count);
        let count = *count as f64;
        data.push(plotlib::repr::BarChart::new(count).label(ch.to_string()));
    }
    // Add data to the view
    let v = data
        .into_iter()
        .fold(plotlib::view::CategoricalView::new(), |view, datum| {
            view.add(datum)
        });

    plotlib::page::Page::single(&v)
        .save("barchart.svg")
        .expect("saving svg");
}
Source

pub fn add<R: CategoricalRepresentation + 'static>(self, repr: R) -> Self

Add a representation to the view

Examples found in repository?
examples/barchart_svg.rs (line 12)
6
7
8
9
10
11
12
13
14
15
fn main() {
    let b1 = BarChart::new(5.3).label("1");
    let b2 = BarChart::new(2.6)
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");

    Page::single(&v).save("barchart.svg").expect("saving svg");
}
More examples
Hide additional examples
examples/with_grid.rs (line 33)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn render_barchart<S>(filename: S)
where
    S: AsRef<str>,
{
    let b1 = BarChart::new(5.3).label("1");
    let b2 = BarChart::new(2.6)
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));
    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
    v.add_grid(Grid::new(3, 8));
    Page::single(&v)
        .save(filename.as_ref())
        .expect("saving svg");
}
examples/boxplot_svg.rs (line 13)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let b1 = BoxPlot::from_slice(&[1.0, 4.0, 2.0, 3.5, 6.4, 2.5, 7.5, 1.8, 9.6]).label("1");
    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new()
        .add(b1)
        .add(b2)
        .x_label("Experiment")
        .y_label("y");

    Page::single(&v)
        .dimensions(400, 300)
        .save("boxplot.svg")
        .expect("saving svg");
}
examples/letter_counter.rs (line 24)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let mut data = Vec::new();
    let message: &str = "This is a long message";
    let mut count = BTreeMap::new();

    for c in message.trim().to_lowercase().chars() {
        if c.is_alphabetic() {
            *count.entry(c).or_insert(0) += 1
        }
    }

    println!("Number of occurences per character");
    for (ch, count) in &count {
        println!("{:?}: {}", ch, count);
        let count = *count as f64;
        data.push(plotlib::repr::BarChart::new(count).label(ch.to_string()));
    }
    // Add data to the view
    let v = data
        .into_iter()
        .fold(plotlib::view::CategoricalView::new(), |view, datum| {
            view.add(datum)
        });

    plotlib::page::Page::single(&v)
        .save("barchart.svg")
        .expect("saving svg");
}
Source

pub fn x_ticks(self, ticks: &[String]) -> Self

Set the x range for the view

Source

pub fn y_range(self, min: f64, max: f64) -> Self

Set the y range for the view

Source

pub fn x_label<T>(self, value: T) -> Self
where T: Into<String>,

Set the label for the x-axis

Examples found in repository?
examples/barchart_svg.rs (line 12)
6
7
8
9
10
11
12
13
14
15
fn main() {
    let b1 = BarChart::new(5.3).label("1");
    let b2 = BarChart::new(2.6)
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");

    Page::single(&v).save("barchart.svg").expect("saving svg");
}
More examples
Hide additional examples
examples/with_grid.rs (line 33)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn render_barchart<S>(filename: S)
where
    S: AsRef<str>,
{
    let b1 = BarChart::new(5.3).label("1");
    let b2 = BarChart::new(2.6)
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));
    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
    v.add_grid(Grid::new(3, 8));
    Page::single(&v)
        .save(filename.as_ref())
        .expect("saving svg");
}
examples/boxplot_svg.rs (line 15)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let b1 = BoxPlot::from_slice(&[1.0, 4.0, 2.0, 3.5, 6.4, 2.5, 7.5, 1.8, 9.6]).label("1");
    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new()
        .add(b1)
        .add(b2)
        .x_label("Experiment")
        .y_label("y");

    Page::single(&v)
        .dimensions(400, 300)
        .save("boxplot.svg")
        .expect("saving svg");
}
Source

pub fn y_label<T>(self, value: T) -> Self
where T: Into<String>,

Set the label for the y-axis

Examples found in repository?
examples/boxplot_svg.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let b1 = BoxPlot::from_slice(&[1.0, 4.0, 2.0, 3.5, 6.4, 2.5, 7.5, 1.8, 9.6]).label("1");
    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
        .label("2")
        .style(&BoxStyle::new().fill("darkolivegreen"));

    let v = CategoricalView::new()
        .add(b1)
        .add(b2)
        .x_label("Experiment")
        .y_label("y");

    Page::single(&v)
        .dimensions(400, 300)
        .save("boxplot.svg")
        .expect("saving svg");
}

Trait Implementations§

Source§

impl Default for CategoricalView

Source§

fn default() -> CategoricalView

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

impl View for CategoricalView

Source§

fn to_svg(&self, face_width: f64, face_height: f64) -> Result<Group, Error>

Source§

fn to_text(&self, _face_width: u32, _face_height: u32) -> Result<String, Error>

Source§

fn add_grid(&mut self, grid: Grid)

Source§

fn grid(&self) -> &Option<Grid>

Auto Trait Implementations§

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> 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, 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.