Skip to content

Commit f6b34e4

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

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
""" pyplots.ai
2+
contour-filled: Filled Contour Plot
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
11+
# Data - create a meshgrid with an interesting mathematical surface
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 a surface with multiple Gaussian peaks and a saddle point
18+
# This demonstrates various features: peaks, valleys, and gradients
19+
Z = (
20+
1.5 * np.exp(-((X - 1) ** 2 + (Y - 1) ** 2)) # Peak at (1, 1)
21+
+ 1.2 * np.exp(-((X + 1.5) ** 2 + (Y + 1) ** 2) / 1.5) # Peak at (-1.5, -1)
22+
- 0.8 * np.exp(-((X + 0.5) ** 2 + (Y - 1.5) ** 2) / 0.8) # Valley at (-0.5, 1.5)
23+
+ 0.5 * np.exp(-((X - 1.5) ** 2 + (Y + 1.5) ** 2)) # Small peak at (1.5, -1.5)
24+
)
25+
26+
# Create figure
27+
fig, ax = plt.subplots(figsize=(16, 9))
28+
29+
# Define number of contour levels for smooth transitions
30+
levels = 15
31+
32+
# Create filled contour plot with a sequential colormap
33+
contourf = ax.contourf(X, Y, Z, levels=levels, cmap="viridis")
34+
35+
# Overlay contour lines for precise level identification
36+
ax.contour(X, Y, Z, levels=levels, colors="white", linewidths=0.8, alpha=0.5)
37+
38+
# Add colorbar to indicate value mapping
39+
cbar = plt.colorbar(contourf, ax=ax, shrink=0.9, pad=0.02)
40+
cbar.set_label("Surface Height (z)", fontsize=20)
41+
cbar.ax.tick_params(labelsize=16)
42+
43+
# Styling
44+
ax.set_xlabel("X Position", fontsize=20)
45+
ax.set_ylabel("Y Position", fontsize=20)
46+
ax.set_title("contour-filled · matplotlib · pyplots.ai", fontsize=24)
47+
ax.tick_params(axis="both", labelsize=16)
48+
49+
# Make the plot aspect ratio equal for proper visualization
50+
ax.set_aspect("equal", adjustable="box")
51+
52+
plt.tight_layout()
53+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library: matplotlib
2+
specification_id: contour-filled
3+
created: '2025-12-30T00:02:41Z'
4+
updated: '2025-12-30T00:05:49Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20585400377
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/contour-filled/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/contour-filled/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent mathematical surface with multiple features (peaks, valley, gradients)
17+
that clearly demonstrates filled contour capabilities
18+
- Proper use of viridis colormap which is colorblind-safe and perceptually uniform
19+
- Overlaid white contour lines with appropriate alpha for level identification as
20+
recommended in spec
21+
- Clean KISS code structure following matplotlib best practices
22+
- Correct title format and appropriate font sizes throughout
23+
weaknesses:
24+
- Axis labels could include units (e.g., "X Position (units)" or use a more realistic
25+
application context)
26+
- Mathematical demonstration is generic rather than a compelling real-world scenario
27+
(e.g., topographic elevation, temperature field)
28+
- Could add contour labels (clabel) to show numerical values on contour lines

0 commit comments

Comments
 (0)