Sankey diagram

A Sankey diagram is a type of flow diagram that visually represents the flow of quantities or values between different entities or stages. It illustrates the magnitude and direction of flow as well as the relationship between the entities involved. Sankey diagrams are particularly useful for showing the distribution, transfer, or transformation of resources, energy, or data.

The diagram consists of nodes (representing entities or categories) and directed links (representing flows). The width of the links is proportional to the quantity or value being visualized, allowing for quick comparison and understanding of relative magnitudes. The flow typically starts from a source node and ends at a destination node, with intermediate nodes representing stages or transitions along the flow path.

Sankey diagrams provide a clear visualization of how inputs are transformed and distributed across different pathways or processes. They help identify bottlenecks, inefficiencies, or imbalances in the flow and can be used to analyze and optimize systems or processes. Sankey diagrams are commonly used in fields such as energy management, environmental analysis, logistics, and data visualization to present complex flow data in an intuitive and informative way.

Overall, Sankey diagrams offer a powerful visual representation of the flow and allocation of resources, making it easier to understand and communicate complex relationships and patterns.

Python Example

import plotly.graph_objects as go # Define the nodes nodes = [ dict(label='Node A'), # Source node dict(label='Node B'), # Intermediate node dict(label='Node C'), # Intermediate node dict(label='Node D') # Destination node ] # Define the links links = [ dict(source=0, target=1, value=100), # Flow from Node A to Node B with value 100 dict(source=1, target=2, value=50), # Flow from Node B to Node C with value 50 dict(source=1, target=3, value=50), # Flow from Node B to Node D with value 50 ] # Create the Sankey diagram figure fig = go.Figure(data=[go.Sankey( node=dict( pad=15, # Sets the padding of the nodes thickness=20, # Sets the thickness of the nodes line=dict(color='black', width=0.5), # Sets the color and width of the node borders label=nodes # Assigns the node labels ), link=dict( source=[link['source'] for link in links], # Sets the source nodes of the links target=[link['target'] for link in links], # Sets the target nodes of the links value=[link['value'] for link in links] # Sets the values of the links ) )]) # Customize the layout fig.update_layout(title_text="Example Sankey Diagram", font=dict(size=12, color='black')) # Display the figure fig.show()

In this example, we create a simple Sankey diagram with four nodes (Node A, Node B, Node C, and Node D) and three links representing the flow of values between the nodes. You can customize the labels, colors, and other properties according to your specific requirements.

Sankey Plot result