Skip to content

Commit 2f7710f

Browse files
feat(matplotlib): implement scatter-regression-lowess (#2871)
## Implementation: `scatter-regression-lowess` - matplotlib Implements the **matplotlib** version of `scatter-regression-lowess`. **File:** `plots/scatter-regression-lowess/implementations/matplotlib.py` **Parent Issue:** #2855 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20608460913)* --------- 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 9506fae commit 2f7710f

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
""" pyplots.ai
2+
scatter-regression-lowess: Scatter Plot with LOWESS Regression
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 95/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
from statsmodels.nonparametric.smoothers_lowess import lowess
10+
11+
12+
# Data - create a non-linear relationship that varies across x-axis range
13+
np.random.seed(42)
14+
n_points = 200
15+
x = np.linspace(0, 10, n_points)
16+
# Complex non-linear pattern: sine wave + quadratic trend + noise
17+
y = 2 * np.sin(x * 0.8) + 0.15 * x**2 + np.random.normal(0, 0.8, n_points)
18+
19+
# Compute LOWESS smoothed curve
20+
lowess_result = lowess(y, x, frac=0.3, return_sorted=True)
21+
x_smooth = lowess_result[:, 0]
22+
y_smooth = lowess_result[:, 1]
23+
24+
# Create plot
25+
fig, ax = plt.subplots(figsize=(16, 9))
26+
27+
# Scatter points with transparency
28+
ax.scatter(x, y, s=100, alpha=0.6, color="#306998", edgecolors="white", linewidth=0.5, label="Data points")
29+
30+
# LOWESS regression curve
31+
ax.plot(x_smooth, y_smooth, color="#FFD43B", linewidth=4, label="LOWESS fit", solid_capstyle="round")
32+
33+
# Labels and styling
34+
ax.set_xlabel("Measurement Index", fontsize=20)
35+
ax.set_ylabel("Response Value", fontsize=20)
36+
ax.set_title("scatter-regression-lowess · matplotlib · pyplots.ai", fontsize=24)
37+
ax.tick_params(axis="both", labelsize=16)
38+
ax.legend(fontsize=16, loc="upper left")
39+
ax.grid(True, alpha=0.3, linestyle="--")
40+
41+
plt.tight_layout()
42+
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: scatter-regression-lowess
3+
created: '2025-12-30T23:53:29Z'
4+
updated: '2025-12-30T23:56:03Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20608460913
7+
issue: 2855
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-regression-lowess/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-regression-lowess/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 95
14+
review:
15+
strengths:
16+
- Excellent visualization of LOWESS smoothing on complex non-linear data (sine +
17+
quadratic + noise)
18+
- LOWESS curve is visually distinct with contrasting yellow color and thick line
19+
(linewidth=4)
20+
- Appropriate smoothing bandwidth (frac=0.3) as recommended in spec
21+
- Marker transparency (alpha=0.6) shows data density while keeping LOWESS curve
22+
visible
23+
- Clean, readable code following KISS principles
24+
- All text elements properly sized for high-resolution output
25+
weaknesses:
26+
- Axis labels lack units (e.g., could be "Measurement Index (samples)" or similar)
27+
- Data context is generic "Measurement Index" / "Response Value" - could be more
28+
domain-specific

0 commit comments

Comments
 (0)