Skip to content

Commit 806f55c

Browse files
feat(pygal): implement line-annotated-events (#3139)
## Implementation: `line-annotated-events` - pygal Implements the **pygal** version of `line-annotated-events`. **File:** `plots/line-annotated-events/implementations/pygal.py` **Parent Issue:** #2997 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20627534098)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3d3cf96 commit 806f55c

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
""" pyplots.ai
2+
line-annotated-events: Annotated Line Plot with Event Markers
3+
Library: pygal 3.1.0 | Python 3.13.11
4+
Quality: 72/100 | Created: 2025-12-31
5+
"""
6+
7+
import numpy as np
8+
import pygal
9+
from pygal.style import Style
10+
11+
12+
# Data - Stock price over a year with quarterly events
13+
np.random.seed(42)
14+
n_days = 250 # Trading days in a year
15+
16+
# Generate realistic stock-like price data with trend
17+
base_price = 150
18+
returns = np.random.randn(n_days) * 0.012
19+
prices = base_price * np.cumprod(1 + returns)
20+
21+
# Event data - indices and labels (quarterly earnings + product launch)
22+
events = [(31, "Q4 Earnings"), (94, "Q1 Earnings"), (136, "Product Launch"), (157, "Q2 Earnings"), (220, "Q3 Earnings")]
23+
24+
# Custom style for 4800x2700 canvas with large fonts
25+
custom_style = Style(
26+
background="white",
27+
plot_background="#fafafa",
28+
foreground="#333333",
29+
foreground_strong="#1a1a1a",
30+
foreground_subtle="#666666",
31+
colors=("#306998", "#E74C3C", "#F39C12", "#9B59B6", "#27AE60", "#3498DB"),
32+
title_font_size=72,
33+
label_font_size=42,
34+
major_label_font_size=38,
35+
legend_font_size=42,
36+
value_font_size=36,
37+
value_label_font_size=34,
38+
tooltip_font_size=32,
39+
stroke_width=6,
40+
font_family="sans-serif",
41+
)
42+
43+
# Create XY chart for better control over coordinates
44+
chart = pygal.XY(
45+
width=4800,
46+
height=2700,
47+
style=custom_style,
48+
title="line-annotated-events · pygal · pyplots.ai",
49+
x_title="Trading Day (2024)",
50+
y_title="Stock Price (USD)",
51+
show_dots=False,
52+
stroke_style={"width": 6, "linecap": "round"},
53+
show_legend=True,
54+
legend_at_bottom=True,
55+
legend_at_bottom_columns=3,
56+
show_x_guides=False,
57+
show_y_guides=True,
58+
margin=100,
59+
margin_bottom=200,
60+
margin_left=200,
61+
margin_right=100,
62+
print_values=False,
63+
interpolate="cubic",
64+
range=(min(prices) * 0.95, max(prices) * 1.08),
65+
xrange=(0, n_days),
66+
x_labels_major_count=6,
67+
show_minor_x_labels=False,
68+
)
69+
70+
# Set numeric x-axis labels for trading days
71+
chart.x_labels = [0, 50, 100, 150, 200, 250]
72+
73+
# Add main stock price line as XY coordinates
74+
price_data = [(i, prices[i]) for i in range(n_days)]
75+
chart.add("Stock Price", price_data, stroke_style={"width": 6})
76+
77+
# Add event markers as separate dot series with vertical line effect
78+
# Each event gets its own series for clear legend labeling
79+
y_min = min(prices) * 0.95
80+
y_max = max(prices) * 1.08
81+
82+
for event_idx, label in events:
83+
# Create vertical line effect using multiple points
84+
event_price = prices[event_idx]
85+
# Vertical line from bottom to the event point
86+
vertical_line = [(event_idx, y_min), (event_idx, event_price)]
87+
# Add the vertical line with dashed effect
88+
chart.add(label, vertical_line, stroke_style={"width": 4, "dasharray": "15, 10"}, show_dots=True, dots_size=18)
89+
90+
# Render outputs
91+
chart.render_to_png("plot.png")
92+
chart.render_to_file("plot.html")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: pygal
2+
specification_id: line-annotated-events
3+
created: '2025-12-31T21:33:49Z'
4+
updated: '2025-12-31T22:33:44Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20627534098
7+
issue: 2997
8+
python_version: 3.13.11
9+
library_version: 3.1.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-annotated-events/pygal/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-annotated-events/pygal/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-annotated-events/pygal/plot.html
13+
quality_score: 72
14+
review:
15+
strengths:
16+
- Excellent use of pygal XY chart type for precise coordinate control
17+
- Creative approach to simulate vertical event lines using line segments
18+
- Good custom styling with appropriate font sizes for the large canvas
19+
- Proper color differentiation for each event type
20+
- Clean, well-structured code following KISS principles
21+
- Realistic stock price data with proper volatility characteristics
22+
weaknesses:
23+
- Event labels appear only in the legend, not as text annotations directly on the
24+
chart near the event markers (spec requests text labels at events)
25+
- Vertical dashed lines could be more prominent (thicker stroke or bolder dashing)

0 commit comments

Comments
 (0)