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

Adjusting Popup Layout and Text


In [1]:
from plotapi import Sankey

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


Plotapi Sankey makes use of popups (tooltips) to display more information when mousing over a node or link.

Let's see how we can add to the popup text and adjust the layout and template variables.

As we can see, we have set our license details in the preamble with Sankey.set_license().


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

We can add a description to each link to have it display within the popup.

We can add descriptions to nodes by creating a node data structure that we will pass into Plotapi later.

In [21]:
links = [
    {"source":"Group A", "target":"Rank 1", "value": 1000, "description": "This was a <b>great</b> transition"},
    {"source":"Group B", "target":"Rank 1", "value": 300, "description": "This <i>could</i> have gone better"},
    {"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},

nodes = [
    {"name": "Group A", "description": 'Group A is funded by the organisers.<br><img src="">'},
    {"name": "Group B", "description": "A long sentence to demonstrate popup width, a longish but not that long sentence indeed!"}


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


We have included the "description" property in the links and nodes data structures above, meaning they will not appear within the corresponding popups.

We can also set the following parameters:

  • tooltips - true to enable tooltips, false to disable them. Enabled by default.
  • popup_width - to change the popup width.
  • noun - to change the noun used in the popup text, defaults to "instances".
  • link_verb - to change the text used in the link popup text, defaults to "occurs in ".
  • node_verb - to change the text used in the node popup text, defaults to "occurs in ".
  • link_conjunction - to change the text used between the source and target name in a link popup. Defaults to a right-arrow, i.e "\u2192".

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 [24]:
Sankey(links, nodes=nodes,
       popup_width=400, noun="games", link_verb="battled together in ", 
       node_verb="battled in ", link_conjunction="Vs.").show()
Plotapi - Sankey Diagram

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.

Made with Plotapi

You can create beautiful, interactive, and engaging visualisations like this one in any programming language with Plotapi.

Get the Books

Enjoying these notebooks and want more on the subject? Check out the practical books on Data Science, Visualisation, and Evolutionary Algorithms.

Get the books