Skip to main content

mpl_sankey

This is a simple package to produce sankey plots with matplotlib. It is an alternative to the matplotlib.sankey module, which sacrifices some flexibility in exchange for a much simpler interface.

Specifically, this package only produces standard horizontal sankey plots, but it does so automatically from data, rather than requiring the user to figure out the spatial distribution of nodes/flows.

How it works

There is a single method, sankey(), which accepts one argument data and several optional keyword arguments.

data must be a 2-dimensional tabular object with at least 3 columns: best results are obtained with pandas.DataFrames, but numpy.arrays and simple lists of lists are also accepted.

  • each row corresponds to a "flow"
  • the first column stores the weights (that is, the tickness of each flow drawn), and must be an int or float
  • each other column denotes a node (by its label, which can have any type) where the flow passes, at each stage
  • if data is a pandas.DataFrame, then the column names are represented on top of each stage

Example

from mpl_sankey import sankey
from matplotlib import pyplot as plt
import pandas as pd

data = pd.DataFrame([[1, 'a', 1, 'I', 1, 'success'],
                     [2, 'b', 2, 'III', 2, 'discard'],
                     [1, 'b', 1, 'II', 2, 'success'],
                     [1, 'c', 1, 'II', 2, 'discard'],
                     [2.5, 'a', 2, 'IV', 1, 'discard'],
                     [2, 'a', 1, 'I', 1, 'success']],
                    columns=['Weight', 'First', 'Then', 'After', 'Finally', 'Outcome'])

plt.figure(figsize=(12, 3))
sankey(data, cmap=plt.get_cmap('viridis'))
plt.savefig('featured.png', bbox_inches='tight')

Find more in the Examples notebook.

Installation and dependencies

You can install this package through PyPi with pip install mpl_sankey, or just clone the repo from github.

The package requires pandas (and, obviously, matplotlib) to work.

Metadata

Release files for mpl-sankey 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpl-sankey 0.1.0
File Size Uploaded Provenance
mpl_sankey-0.1.0.tar.gz 7.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mpl-sankey 0.1.0
File Interpreter ABI Platform
mpl_sankey-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / mpl_sankey-0.1.0.tar.gz

Download URL mpl_sankey-0.1.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
278cb3f0b6ac48ba05060574603aabdb7cb7012048868c7617ba3075d7235bc4
BLAKE2b-256 checksum
How to use checksums
311fb6237144c709425175a359cd6626733d026052ac0964bb02eca0c3ff0beb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1+

Release files / mpl_sankey-0.1.0-py3-none-any.whl

Download URL mpl_sankey-0.1.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b68485e0228fcf00309256df7354d98d65fc3563dd42f037d428a423c8d8d2c
BLAKE2b-256 checksum
How to use checksums
4fb8b0cac85b930e4a8d687a23527625cb403b0bce7fb736b15c75a40ed261e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1+

Security for mpl-sankey 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page