Skip to main content

Drawing Sankey diagrams in Python

Project description

Sugikey

Description

This package aims at providing a reasonably simple and flexible way to draw Sankey diagrams and related flow diagrams in Python. Sankey diagrams are flow diagrams composed of arrows of width proportional to the flow of e.g. energy or mass. We use the Sugiyama method to derive layered graph layouts, hence the portmanteau Sugi(yama)(San)key.

Some key facts:

  • Consumes pandas dataframes or networkx directed graphs as inputs.
  • Uses NetworkX for processing of the underlying graph structure.
  • Produces visual output with Matplotlib.
  • Limitation: the created diagrams are not interactive, i.e. the arrows cannot be moved. Interactive Sankey diagrams can be created with a variety of other tools, including d3-Sankey.

Have a look at the documentation for more information.

Visuals

image info

Installation

The simplest way to use Sugikey is to install the pypi package: pip install sugikey.

You can also use the Python code from the repository, provided you have installed the required packages. We use Poetry for dependency management.

You will need Python >= 3.10, as well as NetworkX, pandas, Matplotlib and PuLP for layout methods using mathematical optimization. The dependencies are managed with Poetry, which you can use to install the package (see poetry.lock and pyproject.toml).

Usage

The simplest way to use the package are the high-level functions sankey_from_dig and sankey_from_df, which take as input a networkx directed graph and a pandas dataframe, respectively.

import pandas as pd
from sugikey import sankey

# Sankey diagram from a pandas dataframe
flow_df = pd.read_csv(csv_path)
sankey.sankey_from_df(flow_df)
from sugikey import sankey

# Sankey diagram from a networkx directed graph
dig = examples.balanced_tree_with_cross_edge()
sankey.sankey_from_dig(dig)

Have a look at the documentation for more information.

More on Sankey diagrams

Support

Write an issue if there is an issue.

Authors and acknowledgment

Zlatan B.

Project status

This is a personal project without any guarantee. If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sugikey-0.0.2.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sugikey-0.0.2-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file sugikey-0.0.2.tar.gz.

File metadata

  • Download URL: sugikey-0.0.2.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sugikey-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e49ffe595915f9fccabe747aff3286c6e4c9880e449f96c6284c64d5782157da
MD5 e6dff452a6e6a976ec923fd45377834c
BLAKE2b-256 1d68813f372680dd5f6de665d3339f0ca8c50d7baeaafccd6831a9fa22567c83

See more details on using hashes here.

File details

Details for the file sugikey-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sugikey-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for sugikey-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e9c10337fe2c67425d7a334e6d3bbc6e596a05232cff466865f9c113b9806eb
MD5 9eaa8ec5f3e45ce63ce05c6393143eb6
BLAKE2b-256 b0ec5ba6e58107fa7bcde0913809b3a4644b5a0f341ab802d10aefe0cdbe6a8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page