Skip to content

Commit 73b65b7

Browse files
feat(plotnine): implement scatter-regression-lowess (#2869)
## Implementation: `scatter-regression-lowess` - plotnine Implements the **plotnine** version of `scatter-regression-lowess`. **File:** `plots/scatter-regression-lowess/implementations/plotnine.py` **Parent Issue:** #2855 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20608463131)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b791502 commit 73b65b7

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
""" pyplots.ai
2+
scatter-regression-lowess: Scatter Plot with LOWESS Regression
3+
Library: plotnine 0.15.2 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
from plotnine import aes, element_text, geom_point, geom_smooth, ggplot, labs, theme, theme_minimal
10+
11+
12+
# Data - create complex non-linear relationship (crop yield vs temperature)
13+
np.random.seed(42)
14+
n_points = 150
15+
16+
# Temperature range (x) - realistic agricultural context
17+
x = np.linspace(5, 35, n_points)
18+
19+
# Yield (y) - peaks around 20-25°C, drops at extremes (realistic crop response)
20+
# Complex non-linear pattern: quadratic-like with some local variation
21+
y_base = -0.5 * (x - 22) ** 2 + 80 # Peak around 22°C
22+
y_noise = np.random.normal(0, 8, n_points) # Natural variation
23+
y = y_base + y_noise + 3 * np.sin(x / 3) # Add subtle local pattern
24+
25+
# Ensure positive yields
26+
y = np.clip(y, 5, None)
27+
28+
# Create DataFrame
29+
df = pd.DataFrame({"temperature": x, "yield": y})
30+
31+
# Create plot with scatter points and LOWESS smooth
32+
plot = (
33+
ggplot(df, aes(x="temperature", y="yield"))
34+
+ geom_point(color="#306998", alpha=0.6, size=3)
35+
+ geom_smooth(method="lowess", span=0.4, color="#FFD43B", size=2.5, se=False)
36+
+ labs(
37+
x="Temperature (°C)", y="Crop Yield (tons/hectare)", title="scatter-regression-lowess · plotnine · pyplots.ai"
38+
)
39+
+ theme_minimal()
40+
+ theme(
41+
figure_size=(16, 9),
42+
text=element_text(size=14),
43+
axis_title=element_text(size=20),
44+
axis_text=element_text(size=16),
45+
plot_title=element_text(size=24),
46+
)
47+
)
48+
49+
# Save
50+
plot.save("plot.png", dpi=300)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library: plotnine
2+
specification_id: scatter-regression-lowess
3+
created: '2025-12-30T23:52:25Z'
4+
updated: '2025-12-30T23:54:53Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20608463131
7+
issue: 2855
8+
python_version: 3.13.11
9+
library_version: 0.15.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-regression-lowess/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-regression-lowess/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent choice of agricultural context (temperature vs crop yield) that naturally
17+
demonstrates non-linear LOWESS behavior
18+
- Perfect color contrast between blue scatter points and yellow LOWESS curve
19+
- Clean, minimal theme with appropriate text sizing for 4800×2700 resolution
20+
- Well-structured code following KISS principles
21+
- Title format exactly matches specification requirements
22+
weaknesses:
23+
- The LOWESS curve extends slightly below y=0 at the left edge, which is visually
24+
awkward for a yield that should be positive
25+
- The span parameter in geom_smooth may not be correctly controlling the LOWESS
26+
bandwidth

0 commit comments

Comments
 (0)