Visualizations Sankey
Text formatting
The many text formatting options include multi-line label wrapping, size, and color, and much more.
Sample data
Let's import PlotAPI and load our sample data.
from plotapi import Sankey
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},
]
Demonstration
Link labels and template
- We can set the link label colour by passing a HEX colour code or string alias into the
link_label_color
parameter. - We can change the label template by setting
link_numbers_template
to a string that includes<plotapi_value>
where we want the value to appear. - We can disable the link labels entirely by setting
link_numbers=False
.
Sankey(
links,
link_numbers_template="$<plotapi_value>",
link_label_color="white"
).show()
An example of link_numbers
set to False
.
Sankey(links, link_numbers=False).show_png()
Node label position and wrapping
The node labels can be adjusted through a combination of the following:
-
wrap_labels
-true
to enable text wrapping orfalse
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. -
node_word_spacing
- set tonormal
by default. We can set the word spacing by specifying a pixel value, e.g.10px
.
Sankey(
links,
link_color_mode="source",
colors="set2",
link_numbers=False,
node_word_spacing="5px",
vertical_labels=False,
).show()
Another example.
Sankey(
links,
link_color_mode="source",
colors="set3",
link_numbers=False,
horizontal_labels_at_shallowest=False,
horizontal_labels_at_deepest=False,
wrap_labels=False,
node_word_spacing="10px",
).show_png()
Font size
The font-sizes can be adjusted through a combination of the following:
-
title_font_size
- to change the title font-size. -
node_font_size
- to change the node label font-size. -
link_font_size
- to change the link label font-size.
Sankey(links, title="Font-size demonstration",
node_font_size=10,
link_font_size=30,
title_font_size=30).show()
Font color
The font-sizes can be adjusted through a combination of the following:
-
link_label_color
- to change the label color. -
node_label_color
- to change the node label color. -
node_label_stroke
- to change the node label stroke color.
Sankey(links,
link_label_color="red",
node_label_color="white",
node_label_stroke="black").show_png()
Paper-ready font colors
Sankey(links,
link_label_color="black",
node_label_color="black",
node_label_stroke="transparent",
link_background_color="grey").show_png()