Struct plotpy::Histogram [−][src]
pub struct Histogram { /* fields omitted */ }
Expand description
Generates a Histogram plot
Example
// import
use plotpy::{Histogram, Plot};
use std::path::Path;
// directory to save figures
const OUT_DIR: &str = "/tmp/plotpy/doc_tests";
// 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
let path = Path::new(OUT_DIR).join("doc_histogram.svg");
plot.save(&path)?;
Implementations
Sets the width of the lines
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
Sets option to draw stacked histogram
Sets option to skip filling bars
Sets the number of bins