Monday, 23 February 2026

๐Ÿ”€ Day 35: Sankey Diagram in Python

 

๐Ÿ”€ Day 35: Sankey Diagram in Python


๐Ÿ”น What is a Sankey Diagram?

A Sankey Diagram visualizes the flow of quantities from one set of categories to another.

  • Width of the flow = magnitude

  • Nodes = categories

  • Links = movement between categories

It clearly shows how data moves.


๐Ÿ”น When Should You Use It?

Use a Sankey diagram when:

  • Showing energy flow

  • Visualizing budget allocation

  • Tracking user journey

  • Displaying process transitions

  • Showing source → target relationships


๐Ÿ”น Example Scenario

Creative workflow:

  • Inspiration

  • Moodboard

  • Sketch

  • Final Edit

  • Pinterest

  • Instagram


๐Ÿ”น Key Idea Behind It

๐Ÿ‘‰ Nodes represent entities
๐Ÿ‘‰ Links represent flow
๐Ÿ‘‰ Link width shows volume
๐Ÿ‘‰ Best for process visualization

๐Ÿ”น Python Code (Sankey Diagram)

import plotly.graph_objects as go label = ["Inspiration", "Moodboard", "Sketch", "Final Edit", "Pinterest", "Instagram"]
source = [0, 0, 1, 1, 2, 3, 3]
target = [1, 2, 2, 3, 3, 4, 5]
value = [40, 20, 30, 25, 45, 30, 25]
node_colors = ["#E6E2D3", "#DBC1AD", "#A69080", "#C9ADA7", "#9A8C98", "#F2E9E4"] link_colors = "rgba(201, 173, 167, 0.3)" fig = go.Figure(data=[go.Sankey( node = dict(
pad = 30,
thickness = 12,
line = dict(color = "white", width = 1),
label = label, color = node_colors ),
link = dict( source = source, target = target, value = value, color = link_colors
))])
fig.update_layout(
font_size=14,
font_family="serif",
paper_bgcolor="#FAF9F6",
plot_bgcolor="#FAF9F6",
width=1000, height=600,
margin=dict(l=50, r=50, t=50, b=50) )
fig.show()
#source code-->clcoding.com

๐Ÿ”น Updated Output Explanation

  • The workflow begins at Inspiration, which splits into Moodboard and Sketch.

  • From Moodboard, ideas flow further into Sketch and Final Edit.

  • Sketch contributes heavily toward Final Edit (largest flow = 45).

  • Final Edit distributes content to Pinterest and Instagram.

  • The thickness of each connection represents how much effort or volume moves through that path.


Visually, you can clearly see:

๐Ÿ‘‰ Where most creative energy is concentrated
๐Ÿ‘‰ Which stage receives the highest input
๐Ÿ‘‰ How the final output spreads across platforms

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (207) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (28) Azure (8) BI (10) Books (262) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (299) Cybersecurity (29) data (1) Data Analysis (26) Data Analytics (20) data management (15) Data Science (299) Data Strucures (16) Deep Learning (123) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (18) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (62) Git (9) Google (48) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (249) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (13) PHP (20) Projects (32) Python (1258) Python Coding Challenge (1042) Python Mistakes (50) Python Quiz (427) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (46) Udemy (17) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)