SankeyPlot displays nodes arranged in columns, connected by tapered ribbons that visualize the magnitude and direction of flows between stages. Node heights are proportional to their total throughput, and ribbon widths taper to match the values they carry.
When to Use
Sankey diagrams are ideal for:- Multi-stage pipelines — data processing workflows, variant filtering, quality control
- Budget allocation — resource distribution across departments or projects
- Energy flow — power generation, consumption, and loss visualization
- State transitions — user journey flows, conversion funnels, process states
- Material flow — supply chain, manufacturing processes, ecological cycles
Basic Example
Node Colors and Legend
Set explicit node colors and enable a legend:Ribbon Color Modes
Source Color (Default)
Ribbons inherit the source node’s color:Gradient Ribbons
Each ribbon fades from source to target color using SVG linearGradient:Per-Link Colors
Use explicit colors for individual links:Bioinformatics Example: Variant Filtering Pipeline
Key Methods
SankeyPlot::new()
Create a Sankey diagram with default settings:
- Link color mode: Source
- Link opacity: 0.5
- Node width: 20.0 pixels
- Node gap: 8.0 pixels
.with_link<S: Into<String>>(source: S, target: S, value: f64)
Add a link between two nodes. Nodes are auto-created if they don’t exist. The value determines the ribbon width.
.with_links<S, I>(links: I)
Bulk-add links from an iterator of (source_label, target_label, value) tuples:
.with_node_color<S: Into<String>, C: Into<String>>(label: S, color: C)
Set the color for a node, creating it if absent. Accepts any CSS color string.
.with_node_column<S: Into<String>>(label: S, col: usize)
Pin a node to a specific column (0-indexed). By default, columns are auto-assigned based on the flow topology.
.with_link_colored<S: Into<String>, C: Into<String>>(source: S, target: S, value: f64, color: C)
Add a link with an explicit per-link color. Must call .with_per_link_colors() to enable per-link color mode.
.with_gradient_links()
Use gradient ribbons (linearGradient from source to target color).
.with_per_link_colors()
Use per-link colors (falls back to source color if link.color is None).
.with_link_opacity(opacity: f64)
Set ribbon fill opacity (default 0.5). Range: 0.0 (transparent) to 1.0 (opaque).
.with_node_width(width: f64)
Set node rectangle width in pixels (default 20.0).
.with_node_gap(gap: f64)
Set minimum gap between nodes in a column in pixels (default 8.0).
.with_legend<S: Into<String>>(label: S)
Add a legend with one entry per node.
Data Structures
SankeyPlot
SankeyNode
SankeyLink
SankeyLinkColor
Tips
- Node ordering: Nodes within a column are automatically ordered to minimize ribbon crossings
- Column assignment: Columns are auto-assigned based on longest path from sources; override with
.with_node_column()if needed - Value consistency: Ensure conservation of flow — total input to a node should equal total output
- Color strategy: Use gradient mode for continuous processes, per-link colors for categorizing flows
- Opacity: Reduce opacity when ribbons overlap heavily to improve readability
- Scale: Works well for 5-50 nodes across 2-6 columns
- Legend: Enable when node colors encode categories (stages, types, etc.)
Related Plots
- ChordPlot — For circular pairwise flow matrices without explicit stages
- AlluvialPlot — For tracking categorical membership changes across stages