Skip to content

Commit 04d6a26

Browse files
feat(pygal): implement line-stepwise (#2638)
## Implementation: `line-stepwise` - pygal Implements the **pygal** version of `line-stepwise`. **File:** `plots/line-stepwise/implementations/pygal.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594562908)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2cb62ac commit 04d6a26

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
""" pyplots.ai
2+
line-stepwise: Step Line Plot
3+
Library: pygal 3.1.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import pygal
8+
from pygal.style import Style
9+
10+
11+
# Data - Server response time stepping over 24 hours
12+
hours = list(range(0, 25)) # 0-24 hours
13+
14+
# Response time that steps discretely (server load changes)
15+
response_times = [50] # Start at 50ms
16+
for i in range(1, 25):
17+
# Discrete jumps at certain hours (morning rush, lunch, evening)
18+
if i == 8: # Morning rush
19+
response_times.append(120)
20+
elif i == 12: # Lunch peak
21+
response_times.append(180)
22+
elif i == 14: # Post lunch
23+
response_times.append(100)
24+
elif i == 18: # Evening rush
25+
response_times.append(200)
26+
elif i == 21: # Night decrease
27+
response_times.append(80)
28+
elif i == 23: # Late night
29+
response_times.append(40)
30+
else:
31+
response_times.append(response_times[-1]) # Stay constant
32+
33+
# Create step data by duplicating points for horizontal-then-vertical transitions
34+
# For step-post style: horizontal segment at old value, then vertical jump
35+
step_x_labels = []
36+
step_values = []
37+
for i, (h, v) in enumerate(zip(hours, response_times, strict=True)):
38+
if i == 0:
39+
step_x_labels.append(str(h))
40+
step_values.append(v)
41+
else:
42+
# Add point at new x with OLD y value (horizontal segment)
43+
step_x_labels.append(str(h))
44+
step_values.append(response_times[i - 1])
45+
# Add point at same x with NEW y value (vertical segment)
46+
step_x_labels.append("") # Empty label to avoid clutter
47+
step_values.append(v)
48+
49+
# Custom style for pyplots
50+
custom_style = Style(
51+
background="white",
52+
plot_background="white",
53+
foreground="#333333",
54+
foreground_strong="#333333",
55+
foreground_subtle="#666666",
56+
colors=("#306998",), # Python Blue
57+
title_font_size=56,
58+
label_font_size=36,
59+
major_label_font_size=32,
60+
legend_font_size=32,
61+
value_font_size=28,
62+
stroke_width=5,
63+
)
64+
65+
# Create line chart
66+
chart = pygal.Line(
67+
width=4800,
68+
height=2700,
69+
style=custom_style,
70+
title="line-stepwise · pygal · pyplots.ai",
71+
x_title="Hour of Day",
72+
y_title="Response Time (ms)",
73+
show_dots=False, # Hide dots for cleaner step appearance
74+
fill=False,
75+
show_x_guides=False,
76+
show_y_guides=True,
77+
show_legend=False,
78+
truncate_label=-1,
79+
show_minor_x_labels=True,
80+
x_label_rotation=0,
81+
)
82+
83+
# X-axis labels
84+
chart.x_labels = step_x_labels
85+
86+
# Add step data
87+
chart.add("Server Response", step_values)
88+
89+
# Save outputs
90+
chart.render_to_png("plot.png")
91+
chart.render_to_file("plot.html")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library: pygal
2+
specification_id: line-stepwise
3+
created: '2025-12-30T10:42:35Z'
4+
updated: '2025-12-30T10:50:51Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594562908
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.1.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-stepwise/pygal/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-stepwise/pygal/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-stepwise/pygal/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent step visualization achieved through clever data point duplication for
17+
horizontal-then-vertical transitions
18+
- Clean, professional appearance with appropriate Python Blue color scheme
19+
- Realistic server response time scenario that clearly demonstrates discrete state
20+
changes
21+
- Proper title format and descriptive axis labels with units
22+
- Good font sizing for the 4800x2700 canvas
23+
weaknesses:
24+
- Manual step data construction is verbose; pygal native line interpolation options
25+
could be explored
26+
- Right margin has slight excess whitespace
27+
- Grid only shows Y-axis guides; X-axis guides could improve readability of hour
28+
markers

0 commit comments

Comments
 (0)