Skip to content

Instantly share code, notes, and snippets.

@iraizo
Created March 4, 2021 20:28
Show Gist options
  • Save iraizo/0048b26ec950ccf3cc109627ed8285d6 to your computer and use it in GitHub Desktop.
Save iraizo/0048b26ec950ccf3cc109627ed8285d6 to your computer and use it in GitHub Desktop.
This calculates and visualizes boxplots in rust, i needed this to do some homework because it is tedious to do it yourself.
use plotly::box_plot::{BoxMean, BoxPoints};
use plotly::common::{ErrorData, ErrorType, Line, Marker, Mode, Orientation, Title};
use plotly::histogram::{Bins, Cumulative, HistFunc, HistNorm};
use plotly::layout::{Axis, BarMode, BoxMode, Layout, Margin};
use plotly::{Bar, BoxPlot, Histogram, NamedColor, Plot, Rgb, Rgba, Scatter};
use rand_distr::{Distribution, Normal, Uniform};
fn main() {
let mut y0: Vec<f64> = Vec::new();
let mut y1: Vec<f64> = Vec::new();
// values
y0 = vec![0.9, 1.2, 0.5, 1.1, 0.8, 0.7, 1.0, 1.4, 0.9, 0.7, 1.1, 1.3];
y1 = vec![1.4, 0.8, 1.1, 1.3, 1.5, 1.4, 1.1, 1.9, 1.2, 1.3, 1.7, 1.5];
let trace0 = BoxPlot::<f64, f64>::new(y0);
let trace1 = BoxPlot::<f64, f64>::new(y1);
let mut plot = Plot::new();
plot.add_trace(trace0);
plot.add_trace(trace1);
plot.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment