Skip to main content

lineplot

Function lineplot 

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

Constructs a lineplot from explicit x/y values.

§Examples

use unicode_plot::{lineplot, LineplotOptions};

let x: Vec<f64> = (0..20).map(|i| f64::from(i) * 0.1).collect();
let y: Vec<f64> = x.iter().map(|v| v.sin()).collect();
let plot = lineplot(&x, &y, LineplotOptions::default()).unwrap();

let mut buf = Vec::new();
plot.render(&mut buf, false).unwrap();
assert!(!buf.is_empty());

§Errors

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