Plotting

Plotting with strafe is provided via plots, with a plotters crate backend. You must provide your own drawing area for the plots, either generated from a plotters backend, or from the evcxr instance. Below is an example of plotting the iris dataset from a binary and from evcxr.

Binary Example

use std::error::Error;  
  
use strafe::datasets::iris;  
use strafe::datasets::polars::prelude::*;  
use strafe::plots::prelude::*;  
  
fn main() -> Result<(), Box<dyn Error>> {  
    let iris = iris()?;  
  
    let x = iris  
        .clone()  
        .lazy()  
        .filter(col("Species").eq(lit("setosa")))  
        .collect()?  
        .column("Sepal.Length")?  
        .f64()?  
        .to_vec()  
        .iter()  
        .flatten()  
        .cloned()  
        .collect();  
  
    let y = iris  
        .clone()  
        .lazy()  
        .filter(col("Species").eq(lit("setosa")))  
        .collect()?  
        .column("Sepal.Width")?  
        .f64()?  
        .to_vec()  
        .iter()  
        .flatten()  
        .cloned()  
        .collect();  
  
    let root = SVGBackend::new("plot.svg", (1024, 768)).into_drawing_area();  
    Plot::new()  
        .with_options(PlotOptions {  
            title: "Iris".to_string(),  
            x_axis_label: "Sepal Length".to_string(),  
            y_axis_label: "Sepal Width".to_string(),  
            ..Default::default()  
        })  
        .with_plottable(Points {  
            x,  
            y,  
            ..Default::default()  
        })  
        .plot(&root)?;  
  
    Ok(())  
}

plot.svg

EVCXR Example

Note: Currently having some issues with EVCXR. In theory it should work just fine, but I'm running into two issues.

  1. The long compile time is really killing the workflow. Tried using sccache, but this doesn't seem to be doing anything for some reason? I dunno, maybe I'm doing something wrong. Further research required.
  2. Plotting isn't actually generating a plot like it's supposed to. It just generates a bunch of text that make up the SVG image without actually displaying the SVG image. Also requires more research.

If you have any ideas, pleas leave a comment on the release notes! Thanks!

For more information on evcxr and how to set up Rust in Jupyter Notebooks, see their repo.