Visualizations Sankey
Popup layout and format
The popup supports many customizations, including the text format, width, and disabling it entirely.
Sample data
Let's import PlotAPI and load our sample data.
We can add a description
to each link to have it display within the popup.
We can also add description
s to nodes by creating a node data structure that we will pass into PlotAPI Sankey.
from plotapi import Sankey
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="https://plotapi.com/gallery/images/cards/posts/sankey/getting-started-with-sankey_thumb.thumbnail.jpg">'},
{"name": "Group B", "description": "A long sentence to demonstrate popup width, a longish but not that long sentence indeed!"}
]
Demonstration
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".
Sankey(
links,
colors="league",
nodes=nodes,
popup_width=400,
noun="games",
link_verb="battled together in ",
node_verb="battled in ",
link_conjunction="Vs.",
).show()