Skip to content

Commit 6862fb1

Browse files
feat(seaborn): implement scatter-categorical (#2623)
## Implementation: `scatter-categorical` - seaborn Implements the **seaborn** version of `scatter-categorical`. **File:** `plots/scatter-categorical/implementations/seaborn.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594554074)* --------- 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 079e040 commit 6862fb1

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
""" pyplots.ai
2+
scatter-categorical: Categorical Scatter Plot
3+
Library: seaborn 0.13.2 | Python 3.13.11
4+
Quality: 95/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+
12+
13+
# Data - Iris-like flower measurements with species categories
14+
np.random.seed(42)
15+
16+
# Create data for three flower species with distinct patterns
17+
n_per_group = 50
18+
19+
# Species A: smaller petals, tight cluster
20+
species_a_x = np.random.normal(1.5, 0.3, n_per_group)
21+
species_a_y = np.random.normal(0.3, 0.1, n_per_group)
22+
23+
# Species B: medium petals, wider spread
24+
species_b_x = np.random.normal(4.5, 0.8, n_per_group)
25+
species_b_y = np.random.normal(1.4, 0.3, n_per_group)
26+
27+
# Species C: larger petals, elongated cluster
28+
species_c_x = np.random.normal(5.8, 0.6, n_per_group)
29+
species_c_y = np.random.normal(2.1, 0.4, n_per_group)
30+
31+
df = pd.DataFrame(
32+
{
33+
"Petal Length (cm)": np.concatenate([species_a_x, species_b_x, species_c_x]),
34+
"Petal Width (cm)": np.concatenate([species_a_y, species_b_y, species_c_y]),
35+
"Species": ["Setosa"] * n_per_group + ["Versicolor"] * n_per_group + ["Virginica"] * n_per_group,
36+
}
37+
)
38+
39+
# Plot
40+
fig, ax = plt.subplots(figsize=(16, 9))
41+
42+
# Custom colorblind-safe palette using Python colors first
43+
custom_palette = ["#306998", "#FFD43B", "#6A9F58"]
44+
45+
sns.scatterplot(
46+
data=df,
47+
x="Petal Length (cm)",
48+
y="Petal Width (cm)",
49+
hue="Species",
50+
palette=custom_palette,
51+
s=200,
52+
alpha=0.7,
53+
edgecolor="white",
54+
linewidth=0.5,
55+
ax=ax,
56+
)
57+
58+
# Styling
59+
ax.set_title("scatter-categorical · seaborn · pyplots.ai", fontsize=24, fontweight="bold", pad=20)
60+
ax.set_xlabel("Petal Length (cm)", fontsize=20)
61+
ax.set_ylabel("Petal Width (cm)", fontsize=20)
62+
ax.tick_params(axis="both", labelsize=16)
63+
ax.grid(True, alpha=0.3, linestyle="--")
64+
65+
# Legend styling
66+
ax.legend(title="Species", fontsize=16, title_fontsize=18, loc="upper left", framealpha=0.9)
67+
68+
plt.tight_layout()
69+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library: seaborn
2+
specification_id: scatter-categorical
3+
created: '2025-12-30T10:38:26Z'
4+
updated: '2025-12-30T10:46:52Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594554074
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-categorical/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 95
14+
review:
15+
strengths:
16+
- Excellent use of the Iris flower dataset context - classic, well-understood scientific
17+
scenario
18+
- Perfect text sizing with 24pt title, 20pt labels, 16pt ticks - all highly readable
19+
- Custom colorblind-safe palette with good color contrast between categories
20+
- Clean KISS code structure with proper seed for reproducibility
21+
- Good marker sizing (s=200) and transparency (alpha=0.7) for 150 data points
22+
- White edge borders on markers improve visibility and separation
23+
- Three distinct clusters clearly demonstrate categorical grouping
24+
weaknesses:
25+
- Grid uses dashed linestyle which is slightly more distracting than solid with
26+
low alpha
27+
- Does not utilize seaborn's style parameter to vary marker shapes by category as
28+
suggested in spec
29+
- Could use seaborn's built-in 'colorblind' palette instead of custom colors

0 commit comments

Comments
 (0)