Skip to content

Instantly share code, notes, and snippets.

@dskliarov
Last active September 13, 2025 03:23
Show Gist options
  • Save dskliarov/9dd7f8f13b13ac0cca8bf5bd098d72f4 to your computer and use it in GitHub Desktop.
Save dskliarov/9dd7f8f13b13ac0cca8bf5bd098d72f4 to your computer and use it in GitHub Desktop.
creating sankey diagram
# Create python file sankey.py
import plotly.graph_objects as go
nodes = [
"Received - 100%", # 0
"Bid - 14.190%", # 1
"No matched flights - 68.132%", # 2
"No eligible flights - 12.596%", # 3
"Bidder - 3.133%", # 4
"Privacy CCPA - 1.631%", # 5
"Rate throttled - 0%", # 6
"Privacy TCF - 0.179%", # 7
"Pacing errors - 0.115%", # 8
"User threshold - 0%", # 9
"Auction - 0.024%", # 10
"Bidding timeout - 0%", # 11
"Network timeout - 0%", # 12
"Error - 0%", # 13
"Legitimate no-bid - 83.886%", # 14
"Failures - 0.115%", # 15
"Privacy no-bid - 1.809%" # 16
]
# source nodes
source = [0, # 1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 2 - 13
2, 3, 4, # 14 - 16
5, # 17
6, # 18
7, # 19
8, 9, # 20, 21
10, # 22
11, 12, 13 # 23 - 25
] # Indices of source nodes
# target nodes
target = [1, # 1
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, # 2 - 13
14, 14, 14, # 14 - 16
16, # 17
15, # 18
16, # 19
15, 15, # 20, 21
14, # 22
15, 15, 15 # 23 - 25
] # Indices of target nodes
value = [412929127, # 1
1982708418, 366559980, 91170873, 47455654, 0, 5195757, 3357090, 0, 703979, 886, 36, 20, # 2 - 13
1982708418, 366559980, 91170873, # 14 - 16
47455654, # 17
0, # 18
5195757, # 19
3357090, 0, # 20, 21
703979, # 22
886, 36, 20 # 23 - 25
] # Values of the flows
colors = [
"rgba(64, 103, 237, 0.8)", # 1
"rgba(64, 103, 237, 0.8)", # 2
"rgba(98, 168, 132, 0.8)", # 3
"rgba(176, 154, 107, 0.8)", # 4
"rgba(228, 230, 74, 0.8)", # 5
"rgba(148, 103, 189, 0.8)", # 6
"rgba(140, 86, 75, 0.8)", # 7
"rgba(227, 119, 194, 0.8)", # 8
"rgba(127, 127, 127, 0.8)", # 9
"rgba(188, 189, 34, 0.8)", # 10
"rgba(31, 119, 180, 0.8)", # 11
"rgba(227, 21, 66, 0.8)", # 12
"rgba(255, 127, 14, 0.8)", # 13
"rgba(44, 160, 44, 0.8)", # 14
"rgba(90, 195, 104, 0.8)", # 15
"rgba(148, 103, 189, 0.8)", # 16
"rgba(21, 46, 227, 0.8)" # 17
]
link_colors = [
"rgba(64, 103, 237, 0.2)", # 1
"rgba(110, 110, 110, 0.2)", # 2
"rgba(110, 110, 110, 0.2)", # 3
"rgba(110, 110, 110, 0.2)", # 4
"rgba(110, 110, 110, 0.2)", # 5
"rgba(110, 110, 110, 0.2)", # 6
"rgba(110, 110, 110, 0.2)", # 7
"rgba(110, 110, 110, 0.2)", # 8
"rgba(110, 110, 110, 0.2)", # 9
"rgba(110, 110, 110, 0.2)", # 10
"rgba(110, 110, 110, 0.2)", # 11
"rgba(110, 110, 110, 0.2)", # 12
"rgba(44, 160, 44, 0.3)", # 13
"rgba(44, 160, 44, 0.3)", # 14
"rgba(44, 160, 44, 0.3)", # 15
"rgba(44, 160, 44, 0.3)", # 16
"rgba(21, 46, 227, 0.3)", # 17
"rgba(255,0,255, 0.3)", # 18
"rgba(21, 46, 227, 0.3)", # 19
"rgba(255,0,255, 0.3)", # 20
"rgba(255,0,255, 0.3)", # 21
"rgba(44, 160, 44, 0.3)", # 22
"rgba(255,0,255, 0.3)", # 23
"rgba(255,0,255, 0.3)", # 24
"rgba(255,0,255, 0.3)" # 25
]
fig = go.Figure(data=[go.Sankey(
node=dict(
pad=25,
thickness=30,
line=dict(color="black", width=0.5),
label=nodes, # Use your node labels here
color=colors
),
link=dict(
source=source,
target=target,
value=value,
color=link_colors
))])
fig.update_layout(title_text="Graph description", font_size=20)
fig.show()
# To make the diagram run:
# python sankey.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment