pub struct Histogram { /* private fields */ }Expand description
Generates a Histogram plot
Example
use plotpy::{Histogram, Plot, StrError};
fn main() -> Result<(), StrError> {
// set values
let values = vec![
vec![1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 5, 6], // first series
vec![-1, -1, 0, 1, 2, 3], // second series
vec![5, 6, 7, 8], // third series
];
// set labels
let labels = ["first", "second", "third"];
// configure and draw histogram
let mut histogram = Histogram::new();
histogram.set_colors(&["#9de19a", "#e7eca3", "#98a7f2"])
.set_line_width(10.0)
.set_stacked(true)
.set_style("step");
histogram.draw(&values, &labels);
// add histogram to plot
let mut plot = Plot::new();
plot.add(&histogram)
.set_frame_border(true, false, true, false)
.grid_labels_legend("values", "count");
// save figure
plot.save("/tmp/plotpy/doc_tests/doc_histogram.svg")?;
Ok(())
}See also integration test in the tests directory.
Output from some integration tests:
Implementations
sourceimpl Histogram
impl Histogram
sourcepub fn draw<T, U>(&mut self, values: &Vec<Vec<T>>, labels: &[U]) where
T: Display,
U: Display,
pub fn draw<T, U>(&mut self, values: &Vec<Vec<T>>, labels: &[U]) where
T: Display,
U: Display,
sourcepub fn set_colors(&mut self, colors: &[&str]) -> &mut Self
pub fn set_colors(&mut self, colors: &[&str]) -> &mut Self
Sets the colors for each bar
sourcepub fn set_line_width(&mut self, width: f64) -> &mut Self
pub fn set_line_width(&mut self, width: f64) -> &mut Self
Sets the width of the lines
sourcepub fn set_style(&mut self, style: &str) -> &mut Self
pub fn set_style(&mut self, style: &str) -> &mut Self
Sets the type of histogram
Options:
baris a traditional bar-type histogram. If multiple data are given the bars are arranged side by side.barstackedis a bar-type histogram where multiple data are stacked on top of each other.stepgenerates a lineplot that is by default unfilled.stepfilledgenerates a lineplot that is by default filled.- As defined in https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html
sourcepub fn set_stacked(&mut self, flag: bool) -> &mut Self
pub fn set_stacked(&mut self, flag: bool) -> &mut Self
Sets option to draw stacked histogram
sourcepub fn set_no_fill(&mut self, flag: bool) -> &mut Self
pub fn set_no_fill(&mut self, flag: bool) -> &mut Self
Sets option to skip filling bars
sourcepub fn set_number_bins(&mut self, bins: usize) -> &mut Self
pub fn set_number_bins(&mut self, bins: usize) -> &mut Self
Sets the number of bins
Trait Implementations
sourceimpl GraphMaker for Histogram
impl GraphMaker for Histogram
fn get_buffer<'a>(&'a self) -> &'a String
Auto Trait Implementations
impl RefUnwindSafe for Histogram
impl Send for Histogram
impl Sync for Histogram
impl Unpin for Histogram
impl UnwindSafe for Histogram
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more