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.
Visuals
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.9, 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
Built Distribution
File details
Details for the file sugikey-0.4.0.tar.gz
.
File metadata
- Download URL: sugikey-0.4.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 749921ffdeef42bd1e2850291f96a37f290e0d7dad99628e93ed6bd318fa7600 |
|
MD5 | 9efa2b13c55258f02a2201ff77b27096 |
|
BLAKE2b-256 | 85ccaae68550ec3c228ed3346cfc8fd140bb53a3443ad2e8b7545f6647237fb5 |
File details
Details for the file sugikey-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: sugikey-0.4.0-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ef149f1600d9bbecf29be838f517695d3ff8c1a8516b1af3c0ca0b220047cc3 |
|
MD5 | 62fd251cae8867af18d6782a415c0f16 |
|
BLAKE2b-256 | 9484b7d24d89f40428e506920f7ac32b0d24b9e6422aff152c9bbd1c6b93b001 |