Sankey Diagrams
The following imports have been used to produce the plots below:
#![allow(unused)] fn main() { use itertools_num::linspace; use plotly::common::{ ColorScale, ColorScalePalette, DashType, Fill, Font, Line, LineShape, Marker, Mode, Title, }; use plotly::layout::{Axis, BarMode, Layout, Legend, TicksDirection}; use plotly::Sankey; use rand_distr::{Distribution, Normal, Uniform}; }
The to_inline_html
method is used to produce the html plot displayed in this page.
Constructing a basic Sankey diagram
#![allow(unused)] fn main() { let trace = Sankey::new() .orientation(Orientation::Horizontal) .node( Node::new() .pad(15) .thickness(30) .line(SankeyLine::new().color(NamedColor::Black).width(0.5)) .label(vec!["A1", "A2", "B1", "B2", "C1", "C2"]) .color_array(vec![ NamedColor::Blue, NamedColor::Blue, NamedColor::Blue, NamedColor::Blue, NamedColor::Blue, NamedColor::Blue, ]), ) .link( Link::new() .value(vec![8, 4, 2, 8, 4, 2]) .source(vec![0, 1, 0, 2, 3, 3]) .target(vec![2, 3, 3, 4, 4, 5]), ); let layout = Layout::new() .title("Basic Sankey".into()) .font(Font::new().size(10)); let mut plot = Plot::new(); plot.add_trace(trace); plot.set_layout(layout); if show { plot.show(); } } }