Skip to content

Commit 77e55b3

Browse files
feat(pygal): implement scatter-annotated (#2835)
## Implementation: `scatter-annotated` - pygal Implements the **pygal** version of `scatter-annotated`. **File:** `plots/scatter-annotated/implementations/pygal.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20603305140)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent aeef6b0 commit 77e55b3

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
""" pyplots.ai
2+
scatter-annotated: Annotated Scatter Plot with Text Labels
3+
Library: pygal 3.1.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pygal
9+
from pygal.style import Style
10+
11+
12+
# Data - Company market performance (market cap vs revenue)
13+
np.random.seed(42)
14+
companies = [
15+
"TechFlow",
16+
"DataPrime",
17+
"CloudNine",
18+
"NetWave",
19+
"CodeSphere",
20+
"ByteLogic",
21+
"SoftEdge",
22+
"DevStack",
23+
"AppForge",
24+
"WebCore",
25+
"CyberLink",
26+
"DigiTech",
27+
]
28+
29+
# Generate realistic market cap (x) and revenue (y) data in billions
30+
# Spread out to avoid overlap
31+
market_cap = np.array([15, 45, 75, 105, 135, 25, 55, 85, 115, 145, 35, 95])
32+
revenue = np.array([8, 22, 35, 28, 48, 12, 18, 42, 32, 55, 15, 38])
33+
34+
# Create color palette - cycle through distinct colors for each company
35+
colors = (
36+
"#306998", # Python Blue
37+
"#FFD43B", # Python Yellow
38+
"#E74C3C", # Red
39+
"#2ECC71", # Green
40+
"#9B59B6", # Purple
41+
"#3498DB", # Light Blue
42+
"#E67E22", # Orange
43+
"#1ABC9C", # Teal
44+
"#34495E", # Dark Gray
45+
"#F39C12", # Gold
46+
"#16A085", # Dark Teal
47+
"#8E44AD", # Dark Purple
48+
)
49+
50+
# Custom style for large canvas with larger value font for annotations
51+
custom_style = Style(
52+
background="white",
53+
plot_background="white",
54+
foreground="#333333",
55+
foreground_strong="#333333",
56+
foreground_subtle="#666666",
57+
colors=colors,
58+
title_font_size=48,
59+
label_font_size=32,
60+
major_label_font_size=28,
61+
legend_font_size=24,
62+
value_font_size=28, # Font size for annotations
63+
tooltip_font_size=24,
64+
stroke_width=2,
65+
)
66+
67+
# Store company names for value formatter
68+
company_data = {}
69+
70+
# Create XY chart (scatter plot)
71+
chart = pygal.XY(
72+
width=4800,
73+
height=2700,
74+
style=custom_style,
75+
title="scatter-annotated · pygal · pyplots.ai",
76+
x_title="Market Cap (Billion $)",
77+
y_title="Annual Revenue (Billion $)",
78+
show_legend=True,
79+
legend_at_bottom=True,
80+
legend_at_bottom_columns=6,
81+
show_x_guides=True,
82+
show_y_guides=True,
83+
dots_size=18,
84+
stroke=False,
85+
show_dots=True,
86+
truncate_label=-1,
87+
x_label_rotation=0,
88+
range=(0, 65),
89+
xrange=(0, 165),
90+
print_values=True,
91+
print_values_position="top",
92+
)
93+
94+
# Add each company as individual series with its own color for legend identification
95+
# Use formatter dict to show company name instead of coordinates
96+
for i, company in enumerate(companies):
97+
company_data[(market_cap[i], revenue[i])] = company
98+
chart.add(
99+
company,
100+
[{"value": (market_cap[i], revenue[i]), "label": company, "formatter": lambda x, c=company: c}],
101+
dots_size=20,
102+
formatter=lambda x, c=company: c,
103+
)
104+
105+
# Render to PNG and HTML
106+
chart.render_to_png("plot.png")
107+
chart.render_to_file("plot.html")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: pygal
2+
specification_id: scatter-annotated
3+
created: '2025-12-30T18:37:02Z'
4+
updated: '2025-12-30T18:39:14Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20603305140
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/scatter-annotated/pygal/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/pygal/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/pygal/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent use of individual series per company to achieve distinct colors for
17+
each data point
18+
- Clean annotation placement with company names displayed directly on the chart
19+
using print_values and formatter
20+
- Good use of pygal custom Style for consistent theming with appropriate font sizes
21+
- Well-chosen business context (tech companies market cap vs revenue) that is realistic
22+
and neutral
23+
- Proper canvas size (4800x2700) with appropriately scaled fonts
24+
weaknesses:
25+
- Legend at bottom is redundant with on-chart annotations and appears very small/hard
26+
to read
27+
- Some color pairs are similar (two purples, two greens) which could cause confusion

0 commit comments

Comments
 (0)