Skip to content

Commit acb95ef

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

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
""" pyplots.ai
2+
contour-filled: Filled Contour 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 - Create a meshgrid with multiple Gaussian peaks for interesting contours
12+
np.random.seed(42)
13+
x = np.linspace(-3, 3, 80)
14+
y = np.linspace(-3, 3, 80)
15+
X, Y = np.meshgrid(x, y)
16+
17+
# Create surface with multiple Gaussian peaks and a saddle point
18+
z1 = 2 * np.exp(-((X - 1) ** 2 + (Y - 1) ** 2)) # Peak at (1, 1)
19+
z2 = 1.5 * np.exp(-((X + 1) ** 2 + (Y + 1) ** 2)) # Peak at (-1, -1)
20+
z3 = -1 * np.exp(-((X - 1) ** 2 + (Y + 1) ** 2)) # Valley at (1, -1)
21+
z4 = 0.5 * np.exp(-((X + 1.5) ** 2 + (Y - 1.5) ** 2)) # Smaller peak
22+
Z = z1 + z2 + z3 + z4
23+
24+
# Create filled contour plot
25+
fig = go.Figure()
26+
27+
# Add filled contours
28+
fig.add_trace(
29+
go.Contour(
30+
x=x,
31+
y=y,
32+
z=Z,
33+
colorscale="Viridis",
34+
contours=dict(coloring="heatmap", showlabels=True, labelfont=dict(size=14, color="white")),
35+
colorbar=dict(
36+
title=dict(text="Surface Value", font=dict(size=20)), tickfont=dict(size=16), thickness=25, len=0.9
37+
),
38+
ncontours=15,
39+
line=dict(width=1, color="white"),
40+
)
41+
)
42+
43+
# Update layout for large canvas
44+
fig.update_layout(
45+
title=dict(text="contour-filled · plotly · pyplots.ai", font=dict(size=28), x=0.5, xanchor="center"),
46+
xaxis=dict(
47+
title=dict(text="X Coordinate", font=dict(size=22)),
48+
tickfont=dict(size=18),
49+
showgrid=True,
50+
gridwidth=1,
51+
gridcolor="rgba(128, 128, 128, 0.3)",
52+
),
53+
yaxis=dict(
54+
title=dict(text="Y Coordinate", font=dict(size=22)),
55+
tickfont=dict(size=18),
56+
showgrid=True,
57+
gridwidth=1,
58+
gridcolor="rgba(128, 128, 128, 0.3)",
59+
scaleanchor="x",
60+
scaleratio=1,
61+
),
62+
template="plotly_white",
63+
margin=dict(l=100, r=120, t=100, b=100),
64+
)
65+
66+
# Save as PNG and HTML
67+
fig.write_image("plot.png", width=1600, height=900, scale=3)
68+
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: contour-filled
3+
created: '2025-12-30T00:02:58Z'
4+
updated: '2025-12-30T00:08:55Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20585400365
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-filled/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/contour-filled/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/contour-filled/plotly/plot.html
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent use of Viridis colormap providing colorblind-safe visualization
17+
- Multiple Gaussian peaks and valley demonstrate full capability of filled contours
18+
- Contour labels with white text provide precise value identification
19+
- Well-structured code following KISS principles
20+
- Correct aspect ratio with scaleanchor maintaining square coordinate system
21+
- Both PNG and HTML outputs generated as expected for Plotly
22+
weaknesses:
23+
- Axis labels are generic (X Coordinate, Y Coordinate) without units or more descriptive
24+
context
25+
- Could leverage more Plotly-specific features like custom hovertemplate to show
26+
(x, y, z) values on interaction

0 commit comments

Comments
 (0)