Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

@cvanelteren cvanelteren commented Jan 16, 2026

Add layered Sankey diagram support with flow-aware label placement, expose the layered Sankey API with rc defaults and tests, and include a new gallery example in docs/examples/plot_types to showcase publication-ready Sankey styling and labels.

Closes #457
image

import ultraplot as uplt

fig, ax = uplt.subplots(figsize=(5, 2))
nodes = [
    "Budget",
    "Ops",
    "R&D",
    "Marketing",
    "Infra",
    "People",
    "Product",
    "Campaigns",
    "Savings",
]
flows = [
    dict(source="Budget", target="Ops", value=5, label="Ops", group="ops"),
    dict(source="Budget", target="R&D", value=3, label="R&D", group="rnd"),
    dict(source="Budget", target="Marketing", value=2, label="Mkt", group="mkt"),
    dict(source="Ops", target="Infra", value=2.5, label="Infra", group="ops"),
    dict(source="Ops", target="People", value=2.0, label="People", group="ops"),
    dict(source="R&D", target="Product", value=2.2, label="Prod", group="rnd"),
    dict(source="R&D", target="Savings", value=0.8, label="Save", group="rnd"),
    dict(source="Marketing", target="Campaigns", value=1.7, label="Camps", group="mkt"),
    dict(source="Marketing", target="Savings", value=0.2, label="Save", group="mkt"),
]

ax.sankey(
    nodes=nodes,
    flows=flows,
    style="budget",
    node_label_box=True,  # default rounded white box
    node_label_kw=dict(fontsize=9, color="0.15"),
    flow_labels=True,
    value_format="{:.1f}",
    group_cycle=["#f2a65a", "#7fb069", "#3c91e6"],
    flow_other=0.25,
    other_label="Other",
    node_label_outside="auto",
)
uplt.show(block=1)

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 76.18182% with 131 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/axes/plot_types/sankey.py 77.31% 60 Missing and 33 partials ⚠️
ultraplot/axes/plot.py 44.11% 16 Missing and 22 partials ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add Sankey Diagram

2 participants