Skip to main content

plotly_scatter3dplot/
plotly_scatter3dplot.rs

1use plotlars::polars::prelude::*;
2use plotlars::{CsvReader, Legend, Plot, Rgb, Scatter3dPlot, Shape};
3
4fn main() {
5    let dataset = CsvReader::new("data/penguins.csv")
6        .finish()
7        .unwrap()
8        .lazy()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("bill_length_mm").cast(DataType::Float32),
13            col("flipper_length_mm").cast(DataType::Int16),
14            col("body_mass_g").cast(DataType::Int16),
15        ])
16        .collect()
17        .unwrap();
18
19    Scatter3dPlot::builder()
20        .data(&dataset)
21        .x("body_mass_g")
22        .y("flipper_length_mm")
23        .z("bill_length_mm")
24        .group("species")
25        .opacity(0.25)
26        .size(8)
27        .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
28        .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
29        .plot_title("Scatter 3D Plot")
30        .legend(&Legend::new().x(0.6))
31        .build()
32        .plot();
33}