Skip to main content

stairs

Function stairs 

Source
pub fn stairs<X: ToString, Y: ToString>(
    x: &[X],
    y: &[Y],
    style: StairStyle,
    options: LineplotOptions,
) -> Result<Plot<GridCanvas>, LineplotError>
Expand description

Constructs a staircase plot from explicit x/y values.

§Examples

use unicode_plot::{LineplotOptions, StairStyle, stairs};

let mut options = LineplotOptions::default();
options.title = Some("Example Stairs".to_owned());

let x = vec![1.0, 2.0, 3.0, 4.0];
let y = vec![2.0, 1.0, 3.0, 2.0];
let plot = stairs(&x, &y, StairStyle::Post, options).unwrap();

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

§Errors

Returns LineplotError::LengthMismatch when lengths differ, LineplotError::EmptySeries for empty input, and LineplotError::InvalidNumericValue when parsing fails.