Engaging plots, made easy.

Easily turn your data into engaging visualizations. Powerful API for coders. Powerful app for everyone.

from plotapi import Chord

Chord(matrix, names).show()

Visualizations Sankey

Node and link colors

The color scheme can be set to one of many beautiful presets, or even a customized by supplying a list of colors (HEX, RGB, etc.). Overrides also allow colouring specific nodes.

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},


Setting color schemes

To specify node and link colors, we can set the colors parameter to one of the following:

  • A list of color strings, e.g. ["#264653","#2a9d8f","#e9c46a","#f4a261","#e76f51"]. If there are fewer colors than there are categories, PlotAPI Sankey will loop round the colors.
  • The name of a color scheme from one of the many beautuful presets.

The default color scheme is "rainbow". Let's try a few different color schemes.

Sankey(links, colors="cool").show()
Sankey(links, colors="red_yellow_blue").show_png()
Notebook PNG image
Sankey(links, colors=["#B8D0EB", "cyan", "rgb(111,45,189)"]).show_png()
Notebook PNG image

Overriding specific node colors

We can override specific node colours by constructing and supplying the following data structure. The name corresponds to either a source or target string from the links data structure, and the colour can be a HEX colour code or string alias.

nodes = [
    {"name": "Rank 1", "color": "red"}

Finally, all we need to do is pass in the nodes parameter.

Sankey(links, nodes=nodes, colors=["LightSlateGrey", "DarkSlateGrey"]).show_png()