1use polars::prelude::*;
2
3use plotlars::{Axis, BoxPlot, Legend, Orientation, Plot, Rgb, Text};
4
5fn main() {
6 let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7 .finish()
8 .unwrap()
9 .select([
10 col("species"),
11 col("sex").alias("gender"),
12 col("flipper_length_mm").cast(DataType::Int16),
13 col("body_mass_g").cast(DataType::Int16),
14 ])
15 .collect()
16 .unwrap();
17
18 BoxPlot::builder()
19 .data(&dataset)
20 .labels("species")
21 .values("body_mass_g")
22 .orientation(Orientation::Vertical)
23 .group("gender")
24 .box_points(true)
25 .point_offset(-1.5)
26 .jitter(0.01)
27 .opacity(0.1)
28 .colors(vec![Rgb(0, 191, 255), Rgb(57, 255, 20), Rgb(255, 105, 180)])
29 .plot_title(Text::from("Box Plot").font("Arial").size(18))
30 .x_title(Text::from("species").font("Arial").size(15))
31 .y_title(Text::from("body mass (g)").font("Arial").size(15))
32 .legend_title(Text::from("gender").font("Arial").size(15))
33 .y_axis(&Axis::new().value_thousands(true))
34 .legend(&Legend::new().border_width(1).x(0.9))
35 .build()
36 .plot();
37}