diff --git a/plots/scatter-categorical/implementations/plotly.py b/plots/scatter-categorical/implementations/plotly.py new file mode 100644 index 0000000000..6d1f9b8e43 --- /dev/null +++ b/plots/scatter-categorical/implementations/plotly.py @@ -0,0 +1,74 @@ +""" pyplots.ai +scatter-categorical: Categorical Scatter Plot +Library: plotly 6.5.0 | Python 3.13.11 +Quality: 93/100 | Created: 2025-12-30 +""" + +import numpy as np +import plotly.graph_objects as go + + +# Data - Product performance across regions +np.random.seed(42) +n_per_group = 40 + +# Generate distinct clusters for each region +regions = ["North", "South", "West", "East"] +colors = ["#306998", "#FFD43B", "#8B5CF6", "#10B981"] + +data = { + "North": {"x": np.random.normal(35, 8, n_per_group), "y": np.random.normal(75, 10, n_per_group)}, + "South": {"x": np.random.normal(55, 10, n_per_group), "y": np.random.normal(60, 12, n_per_group)}, + "West": {"x": np.random.normal(70, 7, n_per_group), "y": np.random.normal(85, 8, n_per_group)}, + "East": {"x": np.random.normal(45, 9, n_per_group), "y": np.random.normal(45, 10, n_per_group)}, +} + +# Plot +fig = go.Figure() + +for region, color in zip(regions, colors): + fig.add_trace( + go.Scatter( + x=data[region]["x"], + y=data[region]["y"], + mode="markers", + name=region, + marker=dict(size=14, color=color, opacity=0.7, line=dict(width=1, color="white")), + hovertemplate=f"{region}
Marketing: %{{x:.1f}}%
Sales: %{{y:.1f}}%", + ) + ) + +# Layout +fig.update_layout( + title=dict(text="scatter-categorical · plotly · pyplots.ai", font=dict(size=28), x=0.5, xanchor="center"), + xaxis=dict( + title=dict(text="Marketing Investment (%)", font=dict(size=22)), + tickfont=dict(size=18), + gridcolor="rgba(0,0,0,0.1)", + gridwidth=1, + showgrid=True, + ), + yaxis=dict( + title=dict(text="Sales Growth (%)", font=dict(size=22)), + tickfont=dict(size=18), + gridcolor="rgba(0,0,0,0.1)", + gridwidth=1, + showgrid=True, + ), + legend=dict( + title=dict(text="Region", font=dict(size=20)), + font=dict(size=18), + bordercolor="rgba(0,0,0,0.2)", + borderwidth=1, + x=1.02, + y=0.5, + yanchor="middle", + ), + template="plotly_white", + margin=dict(l=80, r=150, t=80, b=80), + plot_bgcolor="white", +) + +# Save as PNG and HTML +fig.write_image("plot.png", width=1600, height=900, scale=3) +fig.write_html("plot.html", include_plotlyjs="cdn") diff --git a/plots/scatter-categorical/metadata/plotly.yaml b/plots/scatter-categorical/metadata/plotly.yaml new file mode 100644 index 0000000000..f96962a98d --- /dev/null +++ b/plots/scatter-categorical/metadata/plotly.yaml @@ -0,0 +1,26 @@ +library: plotly +specification_id: scatter-categorical +created: '2025-12-30T10:37:46Z' +updated: '2025-12-30T10:44:50Z' +generated_by: claude-opus-4-5-20251101 +workflow_run: 20594554925 +issue: 0 +python_version: 3.13.11 +library_version: 6.5.0 +preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotly/plot.png +preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotly/plot_thumb.png +preview_html: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotly/plot.html +quality_score: 93 +review: + strengths: + - Excellent color palette that is colorblind-accessible (blue, yellow, purple, green) + - Clean layout with proper margins and well-positioned legend + - Good use of hovertemplate for interactive exploration in HTML output + - White marker borders provide visual distinction for overlapping points + - Realistic business context (regional product performance) + - Proper title format following pyplots.ai conventions + weaknesses: + - Grid alpha at 0.1 is perhaps too subtle; 0.2-0.3 would provide better reference + without being distracting + - Legend border is minimal but could be removed entirely for cleaner look + - Some sales growth values exceed 100% which is mathematically possible but unusual