Struct termplot::plot::Histogram

source ·
pub struct Histogram { /* private fields */ }
Expand description

An histogram graph. An approximation of the distribution of data.

Examples

use termplot::*;
use rand::Rng;

let mut rng = rand::thread_rng();
let values: Vec<f64> = (0..100).map(|_| rng.gen_range(0.0f64..10.0f64)).collect();

let mut plot = Plot::default();

plot.set_domain(Domain(0.0..11.0))
    .set_codomain(Domain(0.0..45.0))
    .set_title("Graph title")
    .set_x_label("X axis")
    .set_y_label("Y axis")
    .set_size(Size::new(50, 25))
    .add_plot(Box::new(plot::Histogram::new(
        values,
        vec![0.0..2.0, 2.0..4.0, 4.0..6.0, 6.0..8.0, 8.0..10.0],
    )));

println!("{plot}");

Implementations§

Create an histogram from data and buckets in which the data will be sorted.

For each given value, the value will increment the count of the bucket in which it resides inside.

Create an histogram from data and a number of buckets.

All buckets will have the same width, depending on the range of the min and max value and the number of buckets.

For each given value, the value will increment the count of the bucket in which it resides inside.

Trait Implementations§

Draw the component on the given canvas. Read more

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.