Skip to main content

sankeydiagram/
sankeydiagram.rs

1use plotlars::{Arrangement, Orientation, Plot, Rgb, SankeyDiagram, Text};
2use polars::prelude::*;
3
4fn main() {
5    let dataset = LazyCsvReader::new(PlRefPath::new("data/sankey_flow.csv"))
6        .finish()
7        .unwrap()
8        .collect()
9        .unwrap();
10
11    SankeyDiagram::builder()
12        .data(&dataset)
13        .sources("source")
14        .targets("target")
15        .values("value")
16        .orientation(Orientation::Horizontal)
17        .arrangement(Arrangement::Freeform)
18        .node_colors(vec![
19            Rgb(222, 235, 247),
20            Rgb(198, 219, 239),
21            Rgb(158, 202, 225),
22            Rgb(107, 174, 214),
23            Rgb(66, 146, 198),
24            Rgb(33, 113, 181),
25        ])
26        .link_colors(vec![
27            Rgb(222, 235, 247),
28            Rgb(198, 219, 239),
29            Rgb(158, 202, 225),
30            Rgb(107, 174, 214),
31            Rgb(66, 146, 198),
32            Rgb(33, 113, 181),
33        ])
34        .pad(20)
35        .thickness(30)
36        .plot_title(Text::from("Sankey Diagram").font("Arial").size(18))
37        .build()
38        .plot();
39}