Skip to content

Commit 601fec5

Browse files
feat(plotnine): implement histogram-stepwise (#2660)
## Implementation: `histogram-stepwise` - plotnine Implements the **plotnine** version of `histogram-stepwise`. **File:** `plots/histogram-stepwise/implementations/plotnine.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20595336206)* --------- 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 5b9b438 commit 601fec5

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
""" pyplots.ai
2+
histogram-stepwise: Step Histogram
3+
Library: plotnine 0.15.2 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
from plotnine import aes, element_line, element_text, geom_step, ggplot, labs, scale_color_manual, theme, theme_minimal
10+
11+
12+
# Data - Response times (ms) for two server configurations
13+
np.random.seed(42)
14+
15+
# Configuration A: Standard server setup
16+
config_a = np.random.normal(loc=250, scale=60, size=400)
17+
18+
# Configuration B: Optimized server setup (faster, tighter distribution)
19+
config_b = np.random.normal(loc=180, scale=40, size=400)
20+
21+
# Calculate histograms with shared bins for comparison
22+
n_bins = 30
23+
all_data = np.concatenate([config_a, config_b])
24+
bin_edges = np.linspace(all_data.min() - 10, all_data.max() + 10, n_bins + 1)
25+
26+
# Compute histogram counts for each configuration
27+
counts_a, _ = np.histogram(config_a, bins=bin_edges)
28+
counts_b, _ = np.histogram(config_b, bins=bin_edges)
29+
30+
# Create step data: prepend zero at start, append zero at end for clean closure
31+
# For step histogram: use bin edges (not centers) for x values
32+
step_x_a = np.repeat(bin_edges, 2)[1:-1]
33+
step_y_a = np.repeat(counts_a, 2)
34+
35+
step_x_b = np.repeat(bin_edges, 2)[1:-1]
36+
step_y_b = np.repeat(counts_b, 2)
37+
38+
# Create DataFrames
39+
df_a = pd.DataFrame({"x": step_x_a, "count": step_y_a, "config": "Standard Setup"})
40+
df_b = pd.DataFrame({"x": step_x_b, "count": step_y_b, "config": "Optimized Setup"})
41+
df = pd.concat([df_a, df_b], ignore_index=True)
42+
43+
# Plot
44+
plot = (
45+
ggplot(df, aes(x="x", y="count", color="config"))
46+
+ geom_step(size=2, alpha=0.9)
47+
+ labs(
48+
x="Response Time (ms)", y="Frequency", title="histogram-stepwise · plotnine · pyplots.ai", color="Configuration"
49+
)
50+
+ scale_color_manual(values=["#306998", "#FFD43B"])
51+
+ theme_minimal()
52+
+ theme(
53+
figure_size=(16, 9),
54+
text=element_text(size=14),
55+
axis_title=element_text(size=20),
56+
axis_text=element_text(size=16),
57+
plot_title=element_text(size=24),
58+
legend_text=element_text(size=16),
59+
legend_title=element_text(size=18),
60+
panel_grid_major=element_line(color="#cccccc", size=0.5, alpha=0.3),
61+
panel_grid_minor=element_line(alpha=0.2),
62+
)
63+
)
64+
65+
# Save
66+
plot.save("plot.png", dpi=300, verbose=False)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: plotnine
2+
specification_id: histogram-stepwise
3+
created: '2025-12-30T11:22:17Z'
4+
updated: '2025-12-30T11:29:32Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20595336206
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-stepwise/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/histogram-stepwise/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent implementation of step histogram using geom_step with manually computed
17+
bin edges
18+
- Perfect demonstration of overlaying multiple distributions for comparison (key
19+
application from spec)
20+
- Clean, readable code following KISS principles
21+
- Proper figure sizing (16x9) and text scaling for 4800x2700 output
22+
- Good color contrast between the two distributions
23+
- Realistic and neutral data scenario (server performance comparison)
24+
weaknesses:
25+
- Legend placement inside the plot area could potentially overlap with data in some
26+
cases; consider placing outside
27+
- Manual histogram computation instead of exploring plotnine native histogram capabilities

0 commit comments

Comments
 (0)