A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/sankey-diagram-using-plotly-in-python/ below:

Sankey Diagram using Plotly in Python

Sankey Diagram using Plotly in Python

Last Updated : 15 Jul, 2025

Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library.

Sankey Diagrams

Sankey diagrams are a type of flow diagram in which the width of the arrows is comparative to the flow rate. Sankey diagrams can also visualize the source to represent the source node, target for the target node, value to set the flow volume and label that shows the node name. If the flow is twice as wide it represents double the quantity.

Example 1:

Python3
fig = go.Figure(data=[go.Sankey(
    node = dict(
      thickness = 5,
      line = dict(color = "green", width = 0.1),
      label = ["A", "B", "C", "D", "E", "F"],
      color = "blue"
    ),
    link = dict(
        
      # indices correspond to labels
      source = [0, 6, 1, 4, 2, 3], 
      target = [2, 1, 5, 2, 1, 5],
      value = [7, 1, 3, 6, 9, 4]
  ))])

fig.show()

Output:

Example 2: Styling the graph

Python3
fig = go.Figure(data=[go.Sankey(
    node = dict(
      thickness = 5,
      line = dict(color = "green", width = 0.1),
      label = ["A", "B", "C", "D", "E", "F"],
      color = "blue"
    ),
    link = dict(
        
      # indices correspond to labels
      source = [0, 6, 1, 4, 2, 3], 
      target = [2, 1, 5, 2, 1, 5],
      value = [7, 1, 3, 6, 9, 4]
  ))])

fig.update_layout(
    hovermode = 'x',
    title="Sankey Diagram",
    font=dict(size = 10, color = 'green'),
    plot_bgcolor='blue',
    paper_bgcolor='yellow'
)

fig.show()

Output:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4