Skip to content
Sankey

Sankey

A Sankey diagram.

Sankey

Usage

from dataviz_mojo import sankey
from dataviz_mojo.plot import save

def main() raises:
    var from_stage: List[String] = ["Coal", "Gas", "Coal", "Gas", "Electricity", "Electricity"]
    var to_stage: List[String] = ["Electricity", "Electricity", "Industry", "Industry", "Residential", "Industry"]
    var energy: List[Float64] = [30.0, 20.0, 15.0, 10.0, 25.0, 20.0]

    var c = sankey(from_stage, to_stage, energy)
    save(c, "docs/src/examples/out_sankey.svg")

Args:

  • from_categories: Each flow’s source node, one entry per row. Together with to_categories the edges must form a DAG.
  • to_categories: Each flow’s destination node, one entry per row (paired with from_categories[i]).
  • values: Each flow’s magnitude, sizing its ribbon; must be non-negative.
  • theme: Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – see Theme’s docstring.
  • width: Pixel width of the returned Plot (.size()).
  • height: Pixel height of the returned Plot (.size()).
  • title: The chart’s title, shown above the plot.
  • subtitle: A secondary line shown under the title.
  • x_title: The x-axis caption.
  • y_title: The y-axis caption.