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)
6fn main() {
7    let b1 = BarChart::new(5.3).label("1");
8    let b2 = BarChart::new(2.6)
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
13
14    Page::single(&v).save("barchart.svg").expect("saving svg");
15}
More examples
Hide additional examples
examples/with_grid.rs (line 33)
25fn render_barchart<S>(filename: S)
26where
27    S: AsRef<str>,
28{
29    let b1 = BarChart::new(5.3).label("1");
30    let b2 = BarChart::new(2.6)
31        .label("2")
32        .style(&BoxStyle::new().fill("darkolivegreen"));
33    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
34    v.add_grid(Grid::new(3, 8));
35    Page::single(&v)
36        .save(filename.as_ref())
37        .expect("saving svg");
38}
examples/boxplot_svg.rs (line 12)
6fn main() {
7    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");
8    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new()
13        .add(b1)
14        .add(b2)
15        .x_label("Experiment")
16        .y_label("y");
17
18    Page::single(&v)
19        .dimensions(400, 300)
20        .save("boxplot.svg")
21        .expect("saving svg");
22}
examples/letter_counter.rs (line 23)
3fn main() {
4    let mut data = Vec::new();
5    let message: &str = "This is a long message";
6    let mut count = BTreeMap::new();
7
8    for c in message.trim().to_lowercase().chars() {
9        if c.is_alphabetic() {
10            *count.entry(c).or_insert(0) += 1
11        }
12    }
13
14    println!("Number of occurences per character");
15    for (ch, count) in &count {
16        println!("{:?}: {}", ch, count);
17        let count = *count as f64;
18        data.push(plotlib::repr::BarChart::new(count).label(ch.to_string()));
19    }
20    // Add data to the view
21    let v = data
22        .into_iter()
23        .fold(plotlib::view::CategoricalView::new(), |view, datum| {
24            view.add(datum)
25        });
26
27    plotlib::page::Page::single(&v)
28        .save("barchart.svg")
29        .expect("saving svg");
30}
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)
6fn main() {
7    let b1 = BarChart::new(5.3).label("1");
8    let b2 = BarChart::new(2.6)
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
13
14    Page::single(&v).save("barchart.svg").expect("saving svg");
15}
More examples
Hide additional examples
examples/with_grid.rs (line 33)
25fn render_barchart<S>(filename: S)
26where
27    S: AsRef<str>,
28{
29    let b1 = BarChart::new(5.3).label("1");
30    let b2 = BarChart::new(2.6)
31        .label("2")
32        .style(&BoxStyle::new().fill("darkolivegreen"));
33    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
34    v.add_grid(Grid::new(3, 8));
35    Page::single(&v)
36        .save(filename.as_ref())
37        .expect("saving svg");
38}
examples/boxplot_svg.rs (line 13)
6fn main() {
7    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");
8    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new()
13        .add(b1)
14        .add(b2)
15        .x_label("Experiment")
16        .y_label("y");
17
18    Page::single(&v)
19        .dimensions(400, 300)
20        .save("boxplot.svg")
21        .expect("saving svg");
22}
examples/letter_counter.rs (line 24)
3fn main() {
4    let mut data = Vec::new();
5    let message: &str = "This is a long message";
6    let mut count = BTreeMap::new();
7
8    for c in message.trim().to_lowercase().chars() {
9        if c.is_alphabetic() {
10            *count.entry(c).or_insert(0) += 1
11        }
12    }
13
14    println!("Number of occurences per character");
15    for (ch, count) in &count {
16        println!("{:?}: {}", ch, count);
17        let count = *count as f64;
18        data.push(plotlib::repr::BarChart::new(count).label(ch.to_string()));
19    }
20    // Add data to the view
21    let v = data
22        .into_iter()
23        .fold(plotlib::view::CategoricalView::new(), |view, datum| {
24            view.add(datum)
25        });
26
27    plotlib::page::Page::single(&v)
28        .save("barchart.svg")
29        .expect("saving svg");
30}
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)
6fn main() {
7    let b1 = BarChart::new(5.3).label("1");
8    let b2 = BarChart::new(2.6)
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
13
14    Page::single(&v).save("barchart.svg").expect("saving svg");
15}
More examples
Hide additional examples
examples/with_grid.rs (line 33)
25fn render_barchart<S>(filename: S)
26where
27    S: AsRef<str>,
28{
29    let b1 = BarChart::new(5.3).label("1");
30    let b2 = BarChart::new(2.6)
31        .label("2")
32        .style(&BoxStyle::new().fill("darkolivegreen"));
33    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
34    v.add_grid(Grid::new(3, 8));
35    Page::single(&v)
36        .save(filename.as_ref())
37        .expect("saving svg");
38}
examples/boxplot_svg.rs (line 15)
6fn main() {
7    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");
8    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new()
13        .add(b1)
14        .add(b2)
15        .x_label("Experiment")
16        .y_label("y");
17
18    Page::single(&v)
19        .dimensions(400, 300)
20        .save("boxplot.svg")
21        .expect("saving svg");
22}
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)
6fn main() {
7    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");
8    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new()
13        .add(b1)
14        .add(b2)
15        .x_label("Experiment")
16        .y_label("y");
17
18    Page::single(&v)
19        .dimensions(400, 300)
20        .save("boxplot.svg")
21        .expect("saving svg");
22}

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.