sankeydiagram/
sankeydiagram.rs

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