Skip to content

Commit facd457

Browse files
feat(plotly): implement contour-density (#2567)
## Implementation: `contour-density` - plotly Implements the **plotly** version of `contour-density`. **File:** `plots/contour-density/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20593351187)* --------- 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 414a5ca commit facd457

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
""" pyplots.ai
2+
contour-density: Density Contour Plot
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data - bivariate distribution with multiple clusters
12+
np.random.seed(42)
13+
14+
# Create three clusters to show density variations
15+
n_points = 500
16+
cluster1_x = np.random.normal(2, 0.8, n_points // 3)
17+
cluster1_y = np.random.normal(3, 0.6, n_points // 3)
18+
19+
cluster2_x = np.random.normal(5, 1.0, n_points // 3)
20+
cluster2_y = np.random.normal(5, 0.8, n_points // 3)
21+
22+
cluster3_x = np.random.normal(7, 0.5, n_points // 3)
23+
cluster3_y = np.random.normal(2.5, 0.7, n_points // 3)
24+
25+
x = np.concatenate([cluster1_x, cluster2_x, cluster3_x])
26+
y = np.concatenate([cluster1_y, cluster2_y, cluster3_y])
27+
28+
# Create figure with density contour
29+
fig = go.Figure()
30+
31+
# Add density contour plot
32+
fig.add_trace(
33+
go.Histogram2dContour(
34+
x=x,
35+
y=y,
36+
colorscale=[[0, "rgba(255,255,255,0)"], [0.2, "#FFD43B"], [0.5, "#306998"], [1, "#1a3d5c"]],
37+
contours=dict(showlabels=False, coloring="fill"),
38+
ncontours=12,
39+
showscale=True,
40+
colorbar=dict(title=dict(text="Density", font=dict(size=20)), tickfont=dict(size=16), len=0.8),
41+
line=dict(width=2, color="#306998"),
42+
)
43+
)
44+
45+
# Add scatter points for context (semi-transparent)
46+
fig.add_trace(
47+
go.Scatter(
48+
x=x,
49+
y=y,
50+
mode="markers",
51+
marker=dict(size=8, color="#306998", opacity=0.3, line=dict(width=0)),
52+
showlegend=False,
53+
)
54+
)
55+
56+
# Update layout
57+
fig.update_layout(
58+
title=dict(text="contour-density · plotly · pyplots.ai", font=dict(size=32), x=0.5, xanchor="center"),
59+
xaxis=dict(
60+
title=dict(text="X Variable", font=dict(size=24)),
61+
tickfont=dict(size=18),
62+
showgrid=True,
63+
gridcolor="rgba(0,0,0,0.1)",
64+
gridwidth=1,
65+
),
66+
yaxis=dict(
67+
title=dict(text="Y Variable", font=dict(size=24)),
68+
tickfont=dict(size=18),
69+
showgrid=True,
70+
gridcolor="rgba(0,0,0,0.1)",
71+
gridwidth=1,
72+
),
73+
template="plotly_white",
74+
width=1600,
75+
height=900,
76+
margin=dict(l=100, r=120, t=100, b=100),
77+
)
78+
79+
# Save as PNG and HTML
80+
fig.write_image("plot.png", width=1600, height=900, scale=3)
81+
fig.write_html("plot.html", include_plotlyjs="cdn")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: plotly
2+
specification_id: contour-density
3+
created: '2025-12-30T09:31:21Z'
4+
updated: '2025-12-30T09:39:11Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20593351187
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/contour-density/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/contour-density/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/contour-density/plotly/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent use of filled contours with custom colorscale transitioning from transparent
17+
white to yellow to blue
18+
- Smart combination of density contours with scatter point overlay provides context
19+
as recommended in spec
20+
- Three distinct clusters effectively demonstrate the plot purpose of finding density
21+
patterns
22+
- Clean code structure following KISS principles
23+
- Proper font sizing for 4800x2700 output (scale=3)
24+
weaknesses:
25+
- Axis labels are generic (X Variable, Y Variable) rather than tied to a realistic
26+
context
27+
- Grid lines are too subtle (alpha 0.1) - consider alpha 0.2-0.3 for better visibility

0 commit comments

Comments
 (0)