Skip to content

Commit fcdf14e

Browse files
chore(plotly): add metadata for sankey-basic
1 parent e4fd406 commit fcdf14e

2 files changed

Lines changed: 72 additions & 274 deletions

File tree

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,83 @@
1-
""" pyplots.ai
1+
"""anyplot.ai
22
sankey-basic: Basic Sankey Diagram
3-
Library: plotly 6.5.0 | Python 3.13.11
4-
Quality: 93/100 | Created: 2025-12-23
3+
Library: plotly | Python 3.13
4+
Quality: pending | Updated: 2026-04-30
55
"""
66

7+
import os
8+
79
import plotly.graph_objects as go
810

911

10-
# Data - Energy flow from sources to end-use sectors (in TWh)
12+
# Theme tokens
13+
THEME = os.getenv("ANYPLOT_THEME", "light")
14+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
15+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
16+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
17+
18+
# Okabe-Ito palette for source nodes (positions 1-4)
19+
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2", "#CC79A7"]
20+
SOURCE_RGBA = ["rgba(0,158,115,0.4)", "rgba(213,94,0,0.4)", "rgba(0,114,178,0.4)", "rgba(204,121,167,0.4)"]
21+
22+
# Data - Energy flow from sources to sectors (TWh)
1123
sources = ["Coal", "Natural Gas", "Nuclear", "Renewables"]
1224
targets = ["Residential", "Commercial", "Industrial", "Transportation"]
13-
14-
# Node labels (sources first, then targets)
1525
labels = sources + targets
1626

17-
# Define flows: (source_index, target_index, value)
18-
# Indices: Coal=0, Gas=1, Nuclear=2, Renewables=3
19-
# Residential=4, Commercial=5, Industrial=6, Transportation=7
2027
flows = [
21-
# Coal flows
22-
(0, 4, 5), # Coal -> Residential
23-
(0, 5, 8), # Coal -> Commercial
24-
(0, 6, 25), # Coal -> Industrial
25-
# Natural Gas flows
26-
(1, 4, 22), # Gas -> Residential
27-
(1, 5, 18), # Gas -> Commercial
28-
(1, 6, 15), # Gas -> Industrial
29-
(1, 7, 3), # Gas -> Transportation
30-
# Nuclear flows
31-
(2, 4, 12), # Nuclear -> Residential
32-
(2, 5, 10), # Nuclear -> Commercial
33-
(2, 6, 8), # Nuclear -> Industrial
34-
# Renewables flows
35-
(3, 4, 8), # Renewables -> Residential
36-
(3, 5, 6), # Renewables -> Commercial
37-
(3, 6, 5), # Renewables -> Industrial
38-
(3, 7, 4), # Renewables -> Transportation
28+
(0, 4, 5),
29+
(0, 5, 8),
30+
(0, 6, 25),
31+
(1, 4, 22),
32+
(1, 5, 18),
33+
(1, 6, 15),
34+
(1, 7, 3),
35+
(2, 4, 12),
36+
(2, 5, 10),
37+
(2, 6, 8),
38+
(3, 4, 8),
39+
(3, 5, 6),
40+
(3, 6, 5),
41+
(3, 7, 4),
3942
]
4043

4144
source_indices = [f[0] for f in flows]
4245
target_indices = [f[1] for f in flows]
4346
values = [f[2] for f in flows]
4447

45-
# Colors for source nodes (Python Blue variations and Yellow)
46-
node_colors = [
47-
"#306998", # Coal - Python Blue
48-
"#4A90C2", # Natural Gas - Light Blue
49-
"#FFD43B", # Nuclear - Python Yellow
50-
"#7AB648", # Renewables - Green
51-
"#8FA8BD", # Residential
52-
"#A3B8CC", # Commercial
53-
"#B8C9DB", # Industrial
54-
"#CCD9E8", # Transportation
55-
]
56-
57-
# Link colors with transparency (based on source)
58-
link_colors = [
59-
"rgba(48, 105, 152, 0.5)"
60-
if s == 0
61-
else "rgba(74, 144, 194, 0.5)"
62-
if s == 1
63-
else "rgba(255, 212, 59, 0.5)"
64-
if s == 2
65-
else "rgba(122, 182, 72, 0.5)"
66-
for s in source_indices
67-
]
48+
# Source nodes use Okabe-Ito colors; target nodes use INK_SOFT
49+
node_colors = OKABE_ITO + [INK_SOFT] * 4
50+
link_colors = [SOURCE_RGBA[s] for s in source_indices]
6851

69-
# Create Sankey diagram
52+
# Plot
7053
fig = go.Figure(
7154
data=[
7255
go.Sankey(
73-
node=dict(pad=25, thickness=35, line=dict(color="white", width=2), label=labels, color=node_colors),
74-
link=dict(source=source_indices, target=target_indices, value=values, color=link_colors),
56+
node={
57+
"pad": 25,
58+
"thickness": 35,
59+
"line": {"color": PAGE_BG, "width": 1},
60+
"label": labels,
61+
"color": node_colors,
62+
},
63+
link={"source": source_indices, "target": target_indices, "value": values, "color": link_colors},
7564
)
7665
]
7766
)
7867

79-
# Update layout for 4800x2700 px output
8068
fig.update_layout(
81-
title=dict(
82-
text="Energy Distribution · sankey-basic · plotly · pyplots.ai", font=dict(size=36), x=0.5, xanchor="center"
83-
),
84-
font=dict(size=22),
85-
template="plotly_white",
86-
margin=dict(l=80, r=80, t=120, b=60),
69+
title={
70+
"text": "Energy Distribution · sankey-basic · plotly · anyplot.ai",
71+
"font": {"size": 28, "color": INK},
72+
"x": 0.5,
73+
"xanchor": "center",
74+
},
75+
paper_bgcolor=PAGE_BG,
76+
plot_bgcolor=PAGE_BG,
77+
font={"size": 22, "color": INK},
78+
margin={"l": 80, "r": 80, "t": 120, "b": 60},
8779
)
8880

89-
# Save outputs
90-
fig.write_image("plot.png", width=1600, height=900, scale=3)
91-
fig.write_html("plot.html")
81+
# Save
82+
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
83+
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")
Lines changed: 17 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -1,215 +1,21 @@
1+
# Per-library metadata for plotly implementation of sankey-basic
2+
# Auto-generated by impl-generate.yml
3+
14
library: plotly
5+
language: python
26
specification_id: sankey-basic
37
created: '2025-12-23T19:43:26Z'
4-
updated: '2025-12-23T19:52:16Z'
5-
generated_by: claude-opus-4-5-20251101
6-
workflow_run: 20469993740
7-
issue: 0
8-
python_version: 3.13.11
9-
library_version: 6.5.0
10-
preview_url: https://storage.googleapis.com/anyplot-images/plots/sankey-basic/plotly/plot.png
11-
preview_html: https://storage.googleapis.com/anyplot-images/plots/sankey-basic/plotly/plot.html
12-
quality_score: 93
13-
impl_tags:
14-
dependencies: []
15-
techniques:
16-
- html-export
17-
patterns: []
18-
dataprep: []
19-
styling: []
8+
updated: '2026-04-30T08:55:02Z'
9+
generated_by: claude-sonnet
10+
workflow_run: 25156267074
11+
issue: 810
12+
python_version: 3.13.13
13+
library_version: 6.7.0
14+
preview_url_light: https://storage.googleapis.com/anyplot-images/plots/sankey-basic/python/plotly/plot-light.png
15+
preview_url_dark: https://storage.googleapis.com/anyplot-images/plots/sankey-basic/python/plotly/plot-dark.png
16+
preview_html_light: https://storage.googleapis.com/anyplot-images/plots/sankey-basic/python/plotly/plot-light.html
17+
preview_html_dark: https://storage.googleapis.com/anyplot-images/plots/sankey-basic/python/plotly/plot-dark.html
18+
quality_score: null
2019
review:
21-
strengths:
22-
- Excellent use of Plotly go.Sankey with proper node/link configuration
23-
- Well-chosen color scheme with source-based link coloring and appropriate transparency
24-
- Realistic energy distribution scenario that effectively demonstrates Sankey diagram
25-
purpose
26-
- Clean code structure following KISS principles with clear data organization
27-
- Proper output sizing (1600x900 scale=3) producing 4800x2700 target resolution
28-
weaknesses:
29-
- Could include flow value labels on hover or annotations to show exact TWh values
30-
- Transportation sector only receives flows from Gas and Renewables, missing Coal
31-
and Nuclear contributions
32-
image_description: "The plot displays a Sankey diagram showing energy distribution\
33-
\ from four source nodes (Natural Gas, Nuclear, Renewables, Coal) on the left\
34-
\ to four target nodes (Residential, Commercial, Transportation, Industrial) on\
35-
\ the right. \n\n**Colors**: Source nodes use distinct colors - dark blue for\
36-
\ Coal, light blue for Natural Gas, yellow for Nuclear, and green for Renewables.\
37-
\ Target nodes use muted grayish-blue tones. Flow links are semi-transparent (alpha\
38-
\ ~0.5) and colored to match their source.\n\n**Title**: \"Energy Distribution\
39-
\ · sankey-basic · plotly · pyplots.ai\" centered at top in appropriate font size.\n\
40-
\n**Layout**: The diagram fills the canvas well with adequate margins. Node labels\
41-
\ are positioned clearly next to their respective nodes. Flow widths are proportional\
42-
\ to values, making it easy to identify major pathways (Natural Gas → Residential\
43-
\ being the largest flow)."
44-
criteria_checklist:
45-
visual_quality:
46-
score: 38
47-
max: 40
48-
items:
49-
- id: VQ-01
50-
name: Text Legibility
51-
score: 10
52-
max: 10
53-
passed: true
54-
comment: 'All text clearly readable: title at appropriate size (~36pt), node
55-
labels at ~22pt, all crisp and legible'
56-
- id: VQ-02
57-
name: No Overlap
58-
score: 8
59-
max: 8
60-
passed: true
61-
comment: No overlapping text; node labels are well-positioned and do not interfere
62-
with flows
63-
- id: VQ-03
64-
name: Element Visibility
65-
score: 8
66-
max: 8
67-
passed: true
68-
comment: Flow links appropriately sized with 0.5 opacity allowing visibility
69-
where flows cross
70-
- id: VQ-04
71-
name: Color Accessibility
72-
score: 5
73-
max: 5
74-
passed: true
75-
comment: Color scheme uses blue, yellow, green which are colorblind-friendly;
76-
distinct hues for different sources
77-
- id: VQ-05
78-
name: Layout Balance
79-
score: 5
80-
max: 5
81-
passed: true
82-
comment: Excellent canvas utilization; diagram fills ~70% of space with balanced
83-
margins
84-
- id: VQ-06
85-
name: Axis Labels
86-
score: 0
87-
max: 2
88-
passed: true
89-
comment: N/A for Sankey diagrams (no axes) - applying 2 points for node labels
90-
which are descriptive
91-
- id: VQ-07
92-
name: Grid & Legend
93-
score: 2
94-
max: 2
95-
passed: true
96-
comment: Clean white template, no distracting elements; node colors serve
97-
as implicit legend
98-
spec_compliance:
99-
score: 25
100-
max: 25
101-
items:
102-
- id: SC-01
103-
name: Plot Type
104-
score: 8
105-
max: 8
106-
passed: true
107-
comment: Correct Sankey diagram showing flows between nodes
108-
- id: SC-02
109-
name: Data Mapping
110-
score: 5
111-
max: 5
112-
passed: true
113-
comment: Source-target-value correctly mapped; link widths proportional to
114-
flow values
115-
- id: SC-03
116-
name: Required Features
117-
score: 5
118-
max: 5
119-
passed: true
120-
comment: 'All spec features present: distinct colors for sources, link opacity
121-
for crossing flows, clear node labels'
122-
- id: SC-04
123-
name: Data Range
124-
score: 3
125-
max: 3
126-
passed: true
127-
comment: All flows visible and readable
128-
- id: SC-05
129-
name: Legend Accuracy
130-
score: 2
131-
max: 2
132-
passed: true
133-
comment: Node labels accurately describe each category
134-
- id: SC-06
135-
name: Title Format
136-
score: 2
137-
max: 2
138-
passed: true
139-
comment: 'Follows exact format: "Energy Distribution · sankey-basic · plotly
140-
· pyplots.ai"'
141-
data_quality:
142-
score: 18
143-
max: 20
144-
items:
145-
- id: DQ-01
146-
name: Feature Coverage
147-
score: 7
148-
max: 8
149-
passed: true
150-
comment: 'Shows flows from 4 sources to 4 targets with varying magnitudes;
151-
demonstrates multiple flow paths and crossings; minor: could show more dramatic
152-
variation in flow sizes'
153-
- id: DQ-02
154-
name: Realistic Context
155-
score: 7
156-
max: 7
157-
passed: true
158-
comment: Energy distribution from sources (Coal, Gas, Nuclear, Renewables)
159-
to sectors (Residential, Commercial, Industrial, Transportation) is a classic,
160-
comprehensible real-world scenario
161-
- id: DQ-03
162-
name: Appropriate Scale
163-
score: 4
164-
max: 5
165-
passed: true
166-
comment: 'Values in TWh are sensible for energy; Natural Gas having highest
167-
residential flow is realistic; minor: Transportation sector could have more
168-
diverse energy sources'
169-
code_quality:
170-
score: 10
171-
max: 10
172-
items:
173-
- id: CQ-01
174-
name: KISS Structure
175-
score: 3
176-
max: 3
177-
passed: true
178-
comment: 'Simple linear structure: imports → data → colors → figure creation
179-
→ layout → save'
180-
- id: CQ-02
181-
name: Reproducibility
182-
score: 3
183-
max: 3
184-
passed: true
185-
comment: Deterministic data (no random values used)
186-
- id: CQ-03
187-
name: Clean Imports
188-
score: 2
189-
max: 2
190-
passed: true
191-
comment: Only `plotly.graph_objects` imported and used
192-
- id: CQ-04
193-
name: No Deprecated API
194-
score: 1
195-
max: 1
196-
passed: true
197-
comment: Uses current Plotly API (go.Sankey)
198-
- id: CQ-05
199-
name: Output Correct
200-
score: 1
201-
max: 1
202-
passed: true
203-
comment: Saves as `plot.png` and `plot.html`
204-
library_features:
205-
score: 5
206-
max: 5
207-
items:
208-
- id: LF-01
209-
name: Uses distinctive library features
210-
score: 5
211-
max: 5
212-
passed: true
213-
comment: Uses Plotly's interactive Sankey with go.Sankey, custom node padding/thickness,
214-
link transparency, HTML output for interactivity
215-
verdict: APPROVED
20+
strengths: []
21+
weaknesses: []

0 commit comments

Comments
 (0)