Animation Settings and Intro

Preamble

In [1]:
from plotapi import Sankey

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

Introduction

Plotapi Sankey supports animations - both for interactions and for nice introductions to our visualisation.

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 [2]:
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 sources and targets in any arrangement.

Visualisation

We can control the animations with the following:

  • animated_intro - If set to true, will play an animation when the visualisaiton is loaded. This works nicely when paired with the.to_mp4() end-point to create a video.
  • animated_duration - The duration of the intro animation in milliseconds.
  • animated_links_speed - The duration of the animation when traversing each link when mousing over a node.
  • animated_hide_speed - The duration of the animation when moving the mouse out of a node.

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 [10]:
Sankey(links, animated_intro=True, animated_duration=5000,
       animated_links_speed=3000, animated_hide_speed=2000).show()
Plotapi - Sankey Diagram
In [12]:
Sankey(links, animated_intro=True, animated_duration=5000,
       animated_links_speed=3000, animated_hide_speed=2000).show_mp4()

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation.

Node Label Positions and Wrapping

Preamble

In [1]:
from plotapi import Sankey

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

Introduction

The Plotapi Sankey diagram node labels can be customised to enable/disable wrapping or to be displayed horizontally/vertically depending on their depth.

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 [2]:
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 sources and targets in any arrangement.

Visualisation

The node labels can be adjusted through a combination of the following:

  • wrap_labels - true to enable text wrapping or false to disable it, enabled by default.
  • vertical_labels - true to enable vertical node labels, enabled by default.
  • horizontal_labels_at_shallowest - true for the shallowest labels to always be horizontal, enabled by default.
  • horizontal_labels_at_deepest - true for the deepest labels to always be horizontal, enabled by default.

Let's demonstrate these in action.

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_color_mode="source", colors="set2", link_numbers=False,
       vertical_labels=False).show()
Plotapi - Sankey Diagram
In [4]:
Sankey(links, link_color_mode="source", colors="set3", link_numbers=False,
       horizontal_labels_at_shallowest=False, horizontal_labels_at_deepest=False,
       wrap_labels=False).show_png()

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation.

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()