Skip to main content

Make simple, pretty Sankey Diagrams (Beta version)

Project description

pySankey

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

PyPI version Build Status Coverage Status Code style: black

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 pandas as pd
from pysankey import sankey

pd.options.display.max_rows = 8
df = pd.read_csv(
    'pysankey/fruits.txt', sep=' ', names=['true', 'predicted']
)
colorDict = {
    'apple':'#f71b1b',
    'blueberry':'#1b7ef7',
    'banana':'#f3f71b',
    'lime':'#12e23f',
    'orange':'#f78c1b'
}
sankey(
    df['true'], df['predicted'], aspect=20, colorDict=colorDict,
    fontsize=12, figureName="fruit"
)
# Result is in "fruit.png"

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 pandas as pd
from pysankey import sankey

df = pd.read_csv(
    'pysankey/customers-goods.csv', sep=',',
    names=['id', 'customer', 'good', 'revenue']
)
weight = df['revenue'].values[1:].astype(float)
sankey(
    left=df['customer'].values[1:], right=df['good'].values[1:],
    rightWeight=weight, leftWeight=weight, aspect=20, fontsize=20,
    figureName="customer-good"
)
# Result is in "customer-good.png"

Customer goods

Package development

Lint

pylint pysankey

Testing

python -m unittest

Coverage

coverage run -m unittest
coverage html
# Open htmlcov/index.html in a navigator

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

pySankeyBeta-1.0.3.tar.gz (336.0 kB view details)

Uploaded Source

File details

Details for the file pySankeyBeta-1.0.3.tar.gz.

File metadata

  • Download URL: pySankeyBeta-1.0.3.tar.gz
  • Upload date:
  • Size: 336.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

File hashes

Hashes for pySankeyBeta-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1201bb3305de81ed2f152a7bea9e2ba1f530ece61a15c17d79bcd20a366a610d
MD5 bc18e67d226817c7e13688dbce49ac6a
BLAKE2b-256 d6b61cd515052f9c78a8258ae67c79ba1a856ba6f746ef7e022023fa78f0df86

See more details on using hashes here.

Supported by

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