Skip to main content

densityplot

Function densityplot 

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

Constructs a densityplot from explicit x/y values.

Density plots always use CanvasType::Density and disable grid rendering, regardless of the provided LineplotOptions.

§Examples

use unicode_plot::{LineplotOptions, densityplot};

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

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

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

§Errors

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