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(())
}

doc_histogram.svg

See also integration test in the tests directory.

Output from some integration tests:

integ_histogram_1.svg

Implementations

Creates a new Histogram object

Draws histogram

Input
  • values - values
  • labels - labels
Notes
  • The type T must be a number.
  • The type U must be a String or &str.

Sets the colors for each bar

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

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.