Skip to main content

pySankey

Uses matplotlib to create simple Sankey diagrams flowing only from left to right.

Requirements

Requires python-tk (for python 2.7) or python3-tk (for python 3.x) you can install the other requirements with:

    pip install -r requirements.txt

Example

With fruits.txt :

true predicted
0 blueberry orange
1 lime orange
2 blueberry lime
3 apple orange
... ... ...
996 lime orange
997 blueberry orange
998 orange banana
999 apple lime

1000 rows × 2 columns

You can generate a sankey's diagram with this code:

import sankey
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

pd.options.display.max_rows=8
%matplotlib inline

df = pd.read_csv('fruits.txt',sep = ' ',names=['true','predicted'])
colorDict =  {'apple':'#f71b1b','blueberry':'#1b7ef7','banana':'#f3f71b',
              'lime':'#12e23f','orange':'#f78c1b'}
sankey.sankey(df['true'], df['predicted'], aspect=20, colorDict=colorDict,
              fontsize=1, figure_name="fruit")

Fruity Alchemy

You could also use weight:

,customer,good,revenue
0,John,fruit,5.5
1,Mike,meat,11.0
2,Betty,drinks,7.0
3,Ben,fruit,4.0
4,Betty,bread,2.0
5,John,bread,2.5
6,John,drinks,8.0
7,Ben,bread,2.0
8,Mike,bread,3.5
9,John,meat,13.0
import sankey
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
pd.options.display.max_rows=8
%matplotlib inline
df = pd.read_csv('customers-goods.csv',sep = ',',names=['id', 'customer','good','revenue'])
# actual call is left as an exercice to the reader but it could be something like
# sankey.sankey(left=df['customer'], right=df['good'], rightWeight=df['revenue'],
#               aspect=20, colorDict=colorDict, fontsize=20,
#               figure_name="customer-good")

Customer goods

Release files for pySankey 0.0.1

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

Source distribution (sdist)

Source distribution for pySankey 0.0.1
File Size Uploaded
pySankey-0.0.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pySankey 0.0.1
File Interpreter ABI Platform
pySankey-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / pySankey-0.0.1.tar.gz

Download URL pySankey-0.0.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0c50e02242926883ad7a26664b2a79f87111460b6989a8ad090b7d95deb474c0
BLAKE2b-256 checksum
How to use checksums
b3f20a9f3de3ee054fddb1354c5c4a93d72b611d8c5b4dde34f664f1caeeb384
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pySankey-0.0.1-py3-none-any.whl

Download URL pySankey-0.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71e5a3cb3c840cf0d8c4056d53f337c7e833f3c98cff05b9e53fbc79f3c5a0b1
BLAKE2b-256 checksum
How to use checksums
adfcc2823db63e0efe3652759a4de2859ed02fe5479bb1ba720605cd789121e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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