6

Getting started with Plotapi Sankey

 3 years ago
source link: https://datacrayon.com/posts/plotapi/sankey/getting-started-with-sankey/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Preamble

from plotapi import Sankey

Sankey.set_license("your username", "your license key")

Introduction

Your first Plotapi Sankey Diagram! As we can see, we have set our license details in the preamble with Sankey.set_license().

Dataset

Plotapi Sankey expects a list of dictionary items, these will define the flow between a source and a target.

links = [
    {"source":"Group A", "target":"Rank 1", "value": 1000},
    {"source":"Group B", "target":"Rank 1", "value": 300},
    {"source":"Group B", "target":"Rank 2", "value": 600},
    {"source":"Group B", "target":"Rank 3", "value": 400},
    {"source":"Rank 1", "target":"Club A", "value": 700},
    {"source":"Rank 1", "target":"Club B", "value": 400},
    {"source":"Rank 1", "target":"Club C", "value": 200},
    {"source":"Rank 2", "target":"Club B", "value": 200},
    {"source":"Rank 2", "target":"Club C", "value": 400},
    {"source":"Rank 3", "target":"Withdrawn", "value": 400},
    {"source":"Club A", "target":"Prize", "value": 500},
]

We can add many source's and target's in any arrangement.

Visualisation

Creating our first Sankey Diagram is as easy as calling Plotapi with our one input.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

Sankey(links).show()

Plotapi - Sankey Diagram

Group AGroup BRank 1Rank 2Rank 3Club AClub BClub CWithdrawnPrize1000300600400700400200200400400500Produced with Plotapi

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK