Skip to content

Commit 56d4b2b

Browse files
feat(plotly): implement scatter-categorical (#2611)
## Implementation: `scatter-categorical` - plotly Implements the **plotly** version of `scatter-categorical`. **File:** `plots/scatter-categorical/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594554925)* --------- 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 4c8c7fa commit 56d4b2b

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
""" pyplots.ai
2+
scatter-categorical: Categorical Scatter Plot
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 93/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data - Product performance across regions
12+
np.random.seed(42)
13+
n_per_group = 40
14+
15+
# Generate distinct clusters for each region
16+
regions = ["North", "South", "West", "East"]
17+
colors = ["#306998", "#FFD43B", "#8B5CF6", "#10B981"]
18+
19+
data = {
20+
"North": {"x": np.random.normal(35, 8, n_per_group), "y": np.random.normal(75, 10, n_per_group)},
21+
"South": {"x": np.random.normal(55, 10, n_per_group), "y": np.random.normal(60, 12, n_per_group)},
22+
"West": {"x": np.random.normal(70, 7, n_per_group), "y": np.random.normal(85, 8, n_per_group)},
23+
"East": {"x": np.random.normal(45, 9, n_per_group), "y": np.random.normal(45, 10, n_per_group)},
24+
}
25+
26+
# Plot
27+
fig = go.Figure()
28+
29+
for region, color in zip(regions, colors):
30+
fig.add_trace(
31+
go.Scatter(
32+
x=data[region]["x"],
33+
y=data[region]["y"],
34+
mode="markers",
35+
name=region,
36+
marker=dict(size=14, color=color, opacity=0.7, line=dict(width=1, color="white")),
37+
hovertemplate=f"{region}<br>Marketing: %{{x:.1f}}%<br>Sales: %{{y:.1f}}%<extra></extra>",
38+
)
39+
)
40+
41+
# Layout
42+
fig.update_layout(
43+
title=dict(text="scatter-categorical · plotly · pyplots.ai", font=dict(size=28), x=0.5, xanchor="center"),
44+
xaxis=dict(
45+
title=dict(text="Marketing Investment (%)", font=dict(size=22)),
46+
tickfont=dict(size=18),
47+
gridcolor="rgba(0,0,0,0.1)",
48+
gridwidth=1,
49+
showgrid=True,
50+
),
51+
yaxis=dict(
52+
title=dict(text="Sales Growth (%)", font=dict(size=22)),
53+
tickfont=dict(size=18),
54+
gridcolor="rgba(0,0,0,0.1)",
55+
gridwidth=1,
56+
showgrid=True,
57+
),
58+
legend=dict(
59+
title=dict(text="Region", font=dict(size=20)),
60+
font=dict(size=18),
61+
bordercolor="rgba(0,0,0,0.2)",
62+
borderwidth=1,
63+
x=1.02,
64+
y=0.5,
65+
yanchor="middle",
66+
),
67+
template="plotly_white",
68+
margin=dict(l=80, r=150, t=80, b=80),
69+
plot_bgcolor="white",
70+
)
71+
72+
# Save as PNG and HTML
73+
fig.write_image("plot.png", width=1600, height=900, scale=3)
74+
fig.write_html("plot.html", include_plotlyjs="cdn")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library: plotly
2+
specification_id: scatter-categorical
3+
created: '2025-12-30T10:37:46Z'
4+
updated: '2025-12-30T10:44:50Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594554925
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 6.5.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotly/plot.html
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent color palette that is colorblind-accessible (blue, yellow, purple, green)
17+
- Clean layout with proper margins and well-positioned legend
18+
- Good use of hovertemplate for interactive exploration in HTML output
19+
- White marker borders provide visual distinction for overlapping points
20+
- Realistic business context (regional product performance)
21+
- Proper title format following pyplots.ai conventions
22+
weaknesses:
23+
- Grid alpha at 0.1 is perhaps too subtle; 0.2-0.3 would provide better reference
24+
without being distracting
25+
- Legend border is minimal but could be removed entirely for cleaner look
26+
- Some sales growth values exceed 100% which is mathematically possible but unusual

0 commit comments

Comments
 (0)