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
impl CategoricalView
Sourcepub fn new() -> CategoricalView
pub fn new() -> CategoricalView
Create an empty view
Examples found in repository?
More 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");
}
Sourcepub fn add<R: CategoricalRepresentation + 'static>(self, repr: R) -> Self
pub fn add<R: CategoricalRepresentation + 'static>(self, repr: R) -> Self
Add a representation to the view
Examples found in repository?
More 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");
}
Sourcepub fn x_label<T>(self, value: T) -> Self
pub fn x_label<T>(self, value: T) -> Self
Set the label for the x-axis
Examples found in repository?
More 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");
}
Sourcepub fn y_label<T>(self, value: T) -> Self
pub fn y_label<T>(self, value: T) -> Self
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
impl Default for CategoricalView
Source§fn default() -> CategoricalView
fn default() -> CategoricalView
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CategoricalView
impl !RefUnwindSafe for CategoricalView
impl !Send for CategoricalView
impl !Sync for CategoricalView
impl Unpin for CategoricalView
impl !UnwindSafe for CategoricalView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more