Skip to content

Latest commit

 

History

History

SankeyChart

Sankey Chart

Sankey chart is a flow diagram which is able to display mutliple dimension from one state to another states.

Files

The following scripts are used in this chapter:

  • plotlyexample_sankey.py
  • simple_sankey.py

Pacakges Needed

This chapter requires the following packages for the scripts used:

  • Pandas
  • Plotly

Syntax

Data

Data is a list to store go.Sankey(). go.Sankey() consists of two parts: node and link. Sunburst parameters structure is very different different with standard visualization types. No x or y columns are accepted, but alternative arguements!

go.Sankey() has the following parameters:

  • valueformat: Value format used in the hoverinfo
  • valuesuffix: Add suffix after the value displayed in the hoverinfo
  • node: Use to display attribute
    • pad: The size of node pad
    • thickness: The size of thickness
    • label: What to display in the node
    • color: Colour filled in the node
    • line: Setting of the node line
      • color
      • line
  • link: Use to display the fact between two attributes
    • source: Start of the link, use the indices of label in node
    • target: End of the link, use the indices of label in node
    • value: Value of the link
    • color: Colour filled in the link

Plotly Example

fig = go.Figure(data=[go.Sankey(
    node = dict(
      pad = 15,
      thickness = 20,
      line = dict(color = "black", width = 0.5),
      label = ["A1", "A2", "B1", "B2", "C1", "C2"],
      color = ["blue","red","purple","yellow","green","orange"]
    ),
    link = dict(
      source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A1, B1, ...
      target = [2, 3, 3, 4, 4, 5],
      value = [8, 4, 2, 8, 4, 2],
      color = ["lightblue","pink","lightblue","mediumpurple","lightyellow","lightyellow"]
  ))])

fig.update_layout(title_text="Hello World!")

Example - Hours of Video Games Played on Console



See simple_sankey.py for code example.

Reference

Plotly Documentation Sankey Chart