Skip to main content

boxplot

Function boxplot 

Source
pub fn boxplot<L, S, V>(
    labels: &[L],
    series: &[S],
    options: BoxplotOptions,
) -> Result<Plot<BoxplotGraphics>, BoxplotError>
where L: ToString, S: AsRef<[V]>, V: ToString,
Expand description

Constructs a boxplot from one or more numeric series.

§Examples

use unicode_plot::{BoxplotOptions, boxplot};

let mut options = BoxplotOptions::default();
options.title = Some("Example Boxplot".to_owned());

let series = vec![
    vec![1.0, 2.0, 2.5, 3.5, 4.0],
    vec![2.0, 2.2, 2.8, 3.0, 3.7],
];
let plot = boxplot(&["group-a", "group-b"], &series, options).unwrap();

let mut buf = Vec::new();
plot.render(&mut buf, false).unwrap();
let rendered = String::from_utf8(buf).unwrap();
assert!(rendered.contains("Example Boxplot"));

§Errors

Returns BoxplotError::LengthMismatch when labels is non-empty and does not match the number of series, BoxplotError::EmptySeries when no data is provided, BoxplotError::InvalidXLimits for invalid x limits, and BoxplotError::InvalidNumericValue when data fails numeric parsing.