Skip to content

Commit b4d1a0f

Browse files
feat(plotnine): implement histogram-stacked (#2628)
## Implementation: `histogram-stacked` - plotnine Implements the **plotnine** version of `histogram-stacked`. **File:** `plots/histogram-stacked/implementations/plotnine.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594560694)* --------- 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 f0a6899 commit b4d1a0f

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
""" pyplots.ai
2+
histogram-stacked: Stacked Histogram
3+
Library: plotnine 0.15.2 | Python 3.13.11
4+
Quality: 97/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_histogram, ggplot, labs, scale_fill_manual, theme, theme_minimal
10+
11+
12+
# Data - Plant growth measurements across different soil types
13+
np.random.seed(42)
14+
15+
# Generate realistic plant height data for three soil types
16+
soil_a = np.random.normal(loc=25, scale=5, size=150) # Sandy soil
17+
soil_b = np.random.normal(loc=30, scale=6, size=120) # Loamy soil
18+
soil_c = np.random.normal(loc=22, scale=4, size=100) # Clay soil
19+
20+
df = pd.DataFrame(
21+
{
22+
"height": np.concatenate([soil_a, soil_b, soil_c]),
23+
"soil_type": (["Sandy Soil"] * 150 + ["Loamy Soil"] * 120 + ["Clay Soil"] * 100),
24+
}
25+
)
26+
27+
# Create stacked histogram
28+
plot = (
29+
ggplot(df, aes(x="height", fill="soil_type"))
30+
+ geom_histogram(bins=20, position="stack", alpha=0.85, color="white", size=0.3)
31+
+ labs(x="Plant Height (cm)", y="Frequency", title="histogram-stacked · plotnine · pyplots.ai", fill="Soil Type")
32+
+ scale_fill_manual(values=["#306998", "#FFD43B", "#4ECDC4"])
33+
+ theme_minimal()
34+
+ theme(
35+
figure_size=(16, 9),
36+
text=element_text(size=14),
37+
axis_title=element_text(size=20),
38+
axis_text=element_text(size=16),
39+
plot_title=element_text(size=24),
40+
legend_text=element_text(size=16),
41+
legend_title=element_text(size=18),
42+
legend_position="right",
43+
)
44+
)
45+
46+
# Save
47+
plot.save("plot.png", dpi=300)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library: plotnine
2+
specification_id: histogram-stacked
3+
created: '2025-12-30T10:39:17Z'
4+
updated: '2025-12-30T10:49:29Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594560694
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.15.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/histogram-stacked/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/histogram-stacked/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 97
14+
review:
15+
strengths:
16+
- Excellent use of plotnine grammar of graphics with proper stacking via position=stack
17+
- Comprehensive theme customization with appropriate font sizes for 4800x2700 output
18+
- Realistic and engaging data scenario (plant growth across soil types)
19+
- Perfect title format and axis labels with units
20+
- Clean KISS code structure with reproducible seed
21+
- White bar borders enhance visual separation between stacked segments
22+
weaknesses:
23+
- Could use scale_fill_brewer for more colorblind-safe colors instead of manual
24+
hex values

0 commit comments

Comments
 (0)