Skip to content

Commit ef2c4ee

Browse files
feat(matplotlib): implement scatter-annotated (#2822)
## Implementation: `scatter-annotated` - matplotlib Implements the **matplotlib** version of `scatter-annotated`. **File:** `plots/scatter-annotated/implementations/matplotlib.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20602450818)* --------- 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 c69922a commit ef2c4ee

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
""" pyplots.ai
2+
scatter-annotated: Annotated Scatter Plot with Text Labels
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
11+
# Data - Technology companies with market cap and revenue
12+
# Points intentionally spread out to minimize annotation overlap
13+
np.random.seed(42)
14+
companies = [
15+
"TechCorp",
16+
"DataSys",
17+
"CloudNet",
18+
"ByteWorks",
19+
"QuantumAI",
20+
"NexGen",
21+
"CyberFlow",
22+
"InfoPrime",
23+
"CodeLabs",
24+
"DigiCore",
25+
"NetSphere",
26+
"AlgoTech",
27+
"VisionX",
28+
"PulseTech",
29+
"ZetaLogic",
30+
]
31+
# Market cap in billions (x-axis)
32+
market_cap = np.array([55, 135, 105, 18, 225, 70, 120, 45, 165, 85, 30, 195, 150, 175, 60])
33+
# Annual revenue in billions (y-axis)
34+
revenue = np.array([12, 42, 30, 4, 65, 18, 38, 10, 52, 24, 6, 58, 45, 50, 15])
35+
36+
# Create figure (16:9 landscape)
37+
fig, ax = plt.subplots(figsize=(16, 9))
38+
39+
# Scatter plot with Python Blue color
40+
ax.scatter(market_cap, revenue, s=250, alpha=0.7, color="#306998", edgecolors="white", linewidths=2, zorder=3)
41+
42+
# Custom annotation offsets for each point to avoid overlap
43+
# Positive x_offset = right, negative = left
44+
# Positive y_offset = up, negative = down
45+
offsets = [
46+
(10, -10), # TechCorp - below right
47+
(-10, 8), # DataSys - above left
48+
(10, 8), # CloudNet - above right
49+
(-10, -12), # ByteWorks - below left
50+
(10, 8), # QuantumAI - above right
51+
(-10, 8), # NexGen - above left
52+
(10, -10), # CyberFlow - below right
53+
(10, -10), # InfoPrime - below right (adjusted)
54+
(-12, 8), # CodeLabs - above left (adjusted)
55+
(10, 8), # DigiCore - above right
56+
(-10, -10), # NetSphere - below left (adjusted)
57+
(10, -12), # AlgoTech - below right
58+
(10, 8), # VisionX - above right (adjusted)
59+
(10, 10), # PulseTech - above right (adjusted)
60+
(-10, -10), # ZetaLogic - below left (adjusted)
61+
]
62+
63+
# Annotate each point with company name
64+
for i, company in enumerate(companies):
65+
x_offset, y_offset = offsets[i]
66+
ha = "left" if x_offset > 0 else "right"
67+
68+
ax.annotate(
69+
company,
70+
xy=(market_cap[i], revenue[i]),
71+
xytext=(x_offset, y_offset),
72+
textcoords="offset points",
73+
fontsize=13,
74+
color="#333333",
75+
fontweight="medium",
76+
ha=ha,
77+
va="center",
78+
arrowprops={"arrowstyle": "-", "color": "#888888", "lw": 1, "connectionstyle": "arc3,rad=0"},
79+
zorder=4,
80+
)
81+
82+
# Styling
83+
ax.set_xlabel("Market Capitalization ($ Billions)", fontsize=20)
84+
ax.set_ylabel("Annual Revenue ($ Billions)", fontsize=20)
85+
ax.set_title("scatter-annotated · matplotlib · pyplots.ai", fontsize=24)
86+
ax.tick_params(axis="both", labelsize=16)
87+
ax.grid(True, alpha=0.3, linestyle="--", zorder=1)
88+
89+
# Set axis limits with padding
90+
ax.set_xlim(0, 240)
91+
ax.set_ylim(0, 70)
92+
93+
plt.tight_layout()
94+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
library: matplotlib
2+
specification_id: scatter-annotated
3+
created: '2025-12-30T17:49:45Z'
4+
updated: '2025-12-30T18:01:09Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20602450818
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent manual offset positioning for annotations prevents all label overlaps
17+
- Connector lines from labels to points add clarity without visual clutter
18+
- Realistic tech company data with plausible market cap and revenue figures
19+
- Clean, readable code following KISS principles
20+
- Proper font sizing for 4800x2700 output resolution
21+
weaknesses:
22+
- Does not use adjustText or similar library for automatic label placement as suggested
23+
in spec (though manual approach works well for this dataset)

0 commit comments

Comments
 (0)