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§
source§impl Histogram
impl Histogram
sourcepub fn new(values: Vec<f64>, buckets_range: Vec<Range<f64>>) -> Self
pub fn new(values: Vec<f64>, buckets_range: Vec<Range<f64>>) -> Self
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.
sourcepub fn new_with_buckets_count(values: Vec<f64>, count: u32) -> Self
pub fn new_with_buckets_count(values: Vec<f64>, count: u32) -> Self
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.