Plotapi, beautiful by default.

Let plotapi do the heavy lifting – enabling beautiful interactive visualisations with a single line of code (instead of hundreds).

Get Plotapi

Sankey Node Alignment

Preamble

In [ ]:
from plotapi import Sankey

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

Introduction

Plotapi Sankey supports different layouts using the specification of node alignment.

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.

In [ ]:
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":"The Most Amazing Prize", "value": 500},
]

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

Visualisation

We can change how our nodes are arranged using the node_alignment parameter. It supports the following settings: left, right, justify, and center. Let's demonstrate these below.

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

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

In [3]:
Sankey(links, link_numbers=False, node_alignment="right").show()
Plotapi - Sankey Diagram
In [4]:
Sankey(links, link_numbers=False, node_alignment="justify").show_png()
In [5]:
Sankey(links, link_numbers=False, node_alignment="center").show_png()
In [6]:
Sankey(links, link_numbers=False, node_alignment="left").show_png()