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§
source§impl Histogram
impl Histogram
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:
bar
is a traditional bar-type histogram. If multiple data are given the bars are arranged side by side.barstacked
is a bar-type histogram where multiple data are stacked on top of each other.step
generates a lineplot that is by default unfilled.stepfilled
generates 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§
source§impl GraphMaker for Histogram
impl GraphMaker for Histogram
source§fn get_buffer<'a>(&'a self) -> &'a String
fn get_buffer<'a>(&'a self) -> &'a String
Returns the text buffer with Python3 commands
source§fn clear_buffer(&mut self)
fn clear_buffer(&mut self)
Clear the text buffer with Python commands
Auto Trait Implementations§
impl Freeze for Histogram
impl RefUnwindSafe for Histogram
impl Send for Histogram
impl Sync for Histogram
impl Unpin for Histogram
impl UnwindSafe for Histogram
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