Open In App

Sankey Diagram using Plotly in Python

Last Updated : 05 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:



Similar Reads

Define Node position in Sankey Diagram in plotly
Plotly is a Python library which 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 Diagram is used to visualize the flow by
1 min read
How to hide legend with Plotly Express and Plotly in Python?
In this article, we will learn How to hide legend with Plotly Express and Plotly. Here we will discuss two different methods for hiding legend in plotly and plotly express, using two different examples for each to make it more clear. Syntax: For legend: fig.update_traces(showlegend=False)fig.update(layout_showlegend=False) Example 1: In this exampl
2 min read
Plotly - How to show legend in single-trace scatterplot with plotly express?
In this article let's see how to show legend in single-trace scatterplot with plotly express. A 'trace' is the name given to each plot inside the chart. Generally in plotly legend is not visible for single trace scatter plots. Example: In the below, example packages and data are imported and a single trace scatter plot is plotted using px.scatter()
1 min read
Python | Geographical plotting using plotly
Geographical plotting is used for world map as well as states under a country. Mainly used by data analysts to check the agriculture exports or to visualize such data. plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many
2 min read
Plotting graphs using Python's plotly and cufflinks module
plotly is a Python library which 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. cufflink connects plotly with pandas to create g
2 min read
Histogram using Plotly in Python
Plotly is a Python library which 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. Histogram in Plotly A histogram is a graph where
3 min read
How to make a basic Scatterplot using Python-Plotly?
Plotly is a graphing library for making high quality interactive graphs and charts. It is an open source library used for data visualization . This library can be used with three programming languages namely Python, R and Javascript. Using Plotly is very easy and you can make any type of graph using this library. It can generate Statistical charts,
2 min read
Plot Live Graphs using Python Dash and Plotly
Dash is a Python framework built on top of ReactJS, Plotly and Flask. It is used to create interactive web dashboards using just python. Live graphs are particularly necessary for certain applications such as medical tests, stock data, or basically for any kind of data that changes in a very short amount of time where it is not viable to reload eac
4 min read
Treemap using Plotly in Python
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. Treemap in Plotly Treemap in plotly.express is c
3 min read
Bar chart using Plotly in Python
Plotly is a Python library which 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. Bar Chart in Plotly Bar chart with plotly expre
2 min read
Article Tags :
Practice Tags :