Skip to content

harryhaller001/matplotlib-sankey

Repository files navigation

matplotlib-sankey

codecov Version PyPI - Python Version GitHub Actions Workflow Status DOI

Documentation | PyPI | Github repository | Codecov

Sankey plot for matplotlib

Installation

Install with pip:

pip install matplotlib-sankey

Install from source:

git clone https://github.com/harryhaller001/matplotlib-sankey
cd matplotlib-sankey
pip install .

Example

data = [
    # (source index, target index, weight)
    [(0, 2, 20), (0, 1, 10), (3, 4, 15), (3, 2, 10), (5, 1, 5), (5, 2, 50)],
    [(2, 6, 40), (1, 6, 15), (2, 7, 40), (4, 6, 15)],
    [(7, 8, 5), (7, 9, 5), (7, 10, 20), (7, 11, 10), (6, 11, 55), (6, 8, 15)],
]

fig, ax = plt.subplots(figsize=(10, 5))
fig.tight_layout()
sankey(
    data=data,
    cmap="tab20",
    annotate_columns=True,
    ax=ax,
    spacing=0.03,
)

Sankey plot example

Development

python3.10 -m virtualenv venv
source venv/bin/activate

# Install dev dependencies
make install