Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions plots/scatter-categorical/implementations/seaborn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
""" pyplots.ai
scatter-categorical: Categorical Scatter Plot
Library: seaborn 0.13.2 | Python 3.13.11
Quality: 95/100 | Created: 2025-12-30
"""

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns


# Data - Iris-like flower measurements with species categories
np.random.seed(42)

# Create data for three flower species with distinct patterns
n_per_group = 50

# Species A: smaller petals, tight cluster
species_a_x = np.random.normal(1.5, 0.3, n_per_group)
species_a_y = np.random.normal(0.3, 0.1, n_per_group)

# Species B: medium petals, wider spread
species_b_x = np.random.normal(4.5, 0.8, n_per_group)
species_b_y = np.random.normal(1.4, 0.3, n_per_group)

# Species C: larger petals, elongated cluster
species_c_x = np.random.normal(5.8, 0.6, n_per_group)
species_c_y = np.random.normal(2.1, 0.4, n_per_group)

df = pd.DataFrame(
{
"Petal Length (cm)": np.concatenate([species_a_x, species_b_x, species_c_x]),
"Petal Width (cm)": np.concatenate([species_a_y, species_b_y, species_c_y]),
"Species": ["Setosa"] * n_per_group + ["Versicolor"] * n_per_group + ["Virginica"] * n_per_group,
}
)

# Plot
fig, ax = plt.subplots(figsize=(16, 9))

# Custom colorblind-safe palette using Python colors first
custom_palette = ["#306998", "#FFD43B", "#6A9F58"]

sns.scatterplot(
data=df,
x="Petal Length (cm)",
y="Petal Width (cm)",
hue="Species",
palette=custom_palette,
s=200,
alpha=0.7,
edgecolor="white",
linewidth=0.5,
ax=ax,
)

# Styling
ax.set_title("scatter-categorical · seaborn · pyplots.ai", fontsize=24, fontweight="bold", pad=20)
ax.set_xlabel("Petal Length (cm)", fontsize=20)
ax.set_ylabel("Petal Width (cm)", fontsize=20)
ax.tick_params(axis="both", labelsize=16)
ax.grid(True, alpha=0.3, linestyle="--")

# Legend styling
ax.legend(title="Species", fontsize=16, title_fontsize=18, loc="upper left", framealpha=0.9)

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
29 changes: 29 additions & 0 deletions plots/scatter-categorical/metadata/seaborn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library: seaborn
specification_id: scatter-categorical
created: '2025-12-30T10:38:26Z'
updated: '2025-12-30T10:46:52Z'
generated_by: claude-opus-4-5-20251101
workflow_run: 20594554074
issue: 0
python_version: 3.13.11
library_version: 0.13.2
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/seaborn/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/seaborn/plot_thumb.png
preview_html: null
quality_score: 95
review:
strengths:
- Excellent use of the Iris flower dataset context - classic, well-understood scientific
scenario
- Perfect text sizing with 24pt title, 20pt labels, 16pt ticks - all highly readable
- Custom colorblind-safe palette with good color contrast between categories
- Clean KISS code structure with proper seed for reproducibility
- Good marker sizing (s=200) and transparency (alpha=0.7) for 150 data points
- White edge borders on markers improve visibility and separation
- Three distinct clusters clearly demonstrate categorical grouping
weaknesses:
- Grid uses dashed linestyle which is slightly more distracting than solid with
low alpha
- Does not utilize seaborn's style parameter to vary marker shapes by category as
suggested in spec
- Could use seaborn's built-in 'colorblind' palette instead of custom colors