Skip to content

Commit 0fd862f

Browse files
feat(altair): implement scatter-categorical (#2626)
## Implementation: `scatter-categorical` - altair Implements the **altair** version of `scatter-categorical`. **File:** `plots/scatter-categorical/implementations/altair.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594556298)* --------- 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 b4d1a0f commit 0fd862f

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
""" pyplots.ai
2+
scatter-categorical: Categorical Scatter Plot
3+
Library: altair 6.0.0 | Python 3.13.11
4+
Quality: 100/100 | Created: 2025-12-30
5+
"""
6+
7+
import altair as alt
8+
import numpy as np
9+
import pandas as pd
10+
11+
12+
# Data - Iris-like measurements by species
13+
np.random.seed(42)
14+
15+
# Generate measurements for 3 plant species
16+
n_per_species = 50
17+
species_names = ["Setosa", "Versicolor", "Virginica"]
18+
19+
data = []
20+
for i, species in enumerate(species_names):
21+
# Different distributions for each species
22+
base_petal_length = [1.4, 4.2, 5.5][i]
23+
base_petal_width = [0.2, 1.3, 2.0][i]
24+
spread = [0.2, 0.5, 0.6][i]
25+
26+
petal_length = np.random.normal(base_petal_length, spread, n_per_species)
27+
petal_width = np.random.normal(base_petal_width, spread * 0.5, n_per_species)
28+
29+
for pl, pw in zip(petal_length, petal_width, strict=True):
30+
data.append({"Petal Length (cm)": pl, "Petal Width (cm)": pw, "Species": species})
31+
32+
df = pd.DataFrame(data)
33+
34+
# Create chart
35+
chart = (
36+
alt.Chart(df)
37+
.mark_point(size=200, opacity=0.7, filled=True)
38+
.encode(
39+
x=alt.X("Petal Length (cm):Q", title="Petal Length (cm)", scale=alt.Scale(zero=False)),
40+
y=alt.Y("Petal Width (cm):Q", title="Petal Width (cm)", scale=alt.Scale(zero=False)),
41+
color=alt.Color(
42+
"Species:N",
43+
scale=alt.Scale(domain=species_names, range=["#306998", "#FFD43B", "#6B8E23"]),
44+
legend=alt.Legend(title="Species", titleFontSize=20, labelFontSize=18, symbolSize=200),
45+
),
46+
shape=alt.Shape("Species:N", legend=None),
47+
tooltip=["Species:N", "Petal Length (cm):Q", "Petal Width (cm):Q"],
48+
)
49+
.properties(width=1600, height=900, title=alt.Title("scatter-categorical · altair · pyplots.ai", fontSize=28))
50+
.configure_axis(labelFontSize=18, titleFontSize=22, gridOpacity=0.3)
51+
.configure_view(strokeWidth=0)
52+
)
53+
54+
# Save as PNG (4800 x 2700 with scale_factor=3)
55+
chart.save("plot.png", scale_factor=3.0)
56+
57+
# Save as HTML for interactive version
58+
chart.save("plot.html")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
library: altair
2+
specification_id: scatter-categorical
3+
created: '2025-12-30T10:38:39Z'
4+
updated: '2025-12-30T10:49:22Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594556298
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 6.0.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/altair/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/altair/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/altair/plot.html
13+
quality_score: 100
14+
review:
15+
strengths:
16+
- Perfect use of redundant encoding (color + shape) for maximum accessibility
17+
- Well-chosen Iris-inspired data with three clearly separable clusters
18+
- Excellent font sizing across all text elements (title, axes, legend)
19+
- Good use of Altair declarative features including tooltips for interactivity
20+
- Clean code structure following KISS principles
21+
weaknesses: []

0 commit comments

Comments
 (0)