Skip to content

Commit eb1442a

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

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
""" pyplots.ai
2+
scatter-annotated: Annotated Scatter Plot with Text Labels
3+
Library: seaborn 0.13.2 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import pandas as pd
10+
import seaborn as sns
11+
from adjustText import adjust_text
12+
13+
14+
# Set seaborn theme for consistent styling
15+
sns.set_theme(style="whitegrid", palette="colorblind")
16+
17+
# Data: Technology companies with revenue vs market cap
18+
np.random.seed(42)
19+
companies = [
20+
"TechCorp",
21+
"DataSys",
22+
"CloudNet",
23+
"AILabs",
24+
"CyberSec",
25+
"NetFlow",
26+
"AppWorks",
27+
"CodeBase",
28+
"DevOps",
29+
"QuantumX",
30+
"ByteLogic",
31+
"StreamIO",
32+
"VirtualAI",
33+
"SecureIT",
34+
"SmartHub",
35+
]
36+
n_points = len(companies)
37+
38+
# Revenue (billions) and Market Cap (billions) - realistic tech company scale
39+
revenue = np.random.uniform(5, 80, n_points)
40+
market_cap = revenue * np.random.uniform(2, 8, n_points) + np.random.randn(n_points) * 10
41+
42+
# Create DataFrame for seaborn
43+
df = pd.DataFrame({"company": companies, "revenue": revenue, "market_cap": market_cap})
44+
45+
# Create plot
46+
fig, ax = plt.subplots(figsize=(16, 9))
47+
48+
# Use seaborn scatterplot with DataFrame
49+
sns.scatterplot(
50+
data=df,
51+
x="revenue",
52+
y="market_cap",
53+
s=200,
54+
alpha=0.7,
55+
color=sns.color_palette("colorblind")[0],
56+
edgecolor="white",
57+
linewidth=1.5,
58+
ax=ax,
59+
)
60+
61+
# Create text annotations with initial offset (collect for adjustText)
62+
texts = []
63+
for _, row in df.iterrows():
64+
# Start labels slightly offset from points
65+
offset_x = 3.0
66+
offset_y = 12.0
67+
text = ax.text(
68+
row["revenue"] + offset_x,
69+
row["market_cap"] + offset_y,
70+
row["company"],
71+
fontsize=14,
72+
color="#333333",
73+
ha="left",
74+
va="bottom",
75+
)
76+
texts.append(text)
77+
78+
# Use adjustText to prevent label overlaps with connecting lines
79+
adjust_text(
80+
texts,
81+
x=df["revenue"].values,
82+
y=df["market_cap"].values,
83+
arrowprops={"arrowstyle": "-", "color": "#888888", "alpha": 0.6, "lw": 1.0},
84+
expand=(1.5, 1.5),
85+
force_text=(0.3, 0.3),
86+
force_points=(0.3, 0.3),
87+
ax=ax,
88+
)
89+
90+
# Labels and styling
91+
ax.set_xlabel("Annual Revenue ($ Billion)", fontsize=20)
92+
ax.set_ylabel("Market Capitalization ($ Billion)", fontsize=20)
93+
ax.set_title("scatter-annotated · seaborn · pyplots.ai", fontsize=24)
94+
ax.tick_params(axis="both", labelsize=16)
95+
96+
# Adjust axis limits to accommodate labels
97+
ax.set_xlim(0, max(revenue) + 15)
98+
ax.set_ylim(min(market_cap) - 30, max(market_cap) + 60)
99+
100+
plt.tight_layout()
101+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: seaborn
2+
specification_id: scatter-annotated
3+
created: '2025-12-30T17:47:43Z'
4+
updated: '2025-12-30T18:06:41Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20602451004
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.13.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent use of adjustText library for automatic label positioning with subtle
17+
connecting lines
18+
- Proper seaborn theming with whitegrid and colorblind palette
19+
- Text sizes optimized for the 4800x2700 resolution
20+
- Realistic tech company scenario matching spec application examples
21+
- Good marker sizing (s=200) and alpha (0.7) for the data density
22+
- Clean, readable code structure following KISS principles
23+
weaknesses:
24+
- Grid styling could be more subtle (consider reducing grid alpha or using a lighter
25+
style)

0 commit comments

Comments
 (0)