Skip to content

Commit da0f7f1

Browse files
feat(plotnine): implement box-horizontal (#2565)
## Implementation: `box-horizontal` - plotnine Implements the **plotnine** version of `box-horizontal`. **File:** `plots/box-horizontal/implementations/plotnine.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20593349974)* --------- 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 ee3c069 commit da0f7f1

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
""" pyplots.ai
2+
box-horizontal: Horizontal Box Plot
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, coord_flip, element_text, geom_boxplot, ggplot, labs, scale_fill_manual, theme, theme_minimal
10+
11+
12+
# Data - Response times (ms) by service type
13+
np.random.seed(42)
14+
15+
services = [
16+
"Authentication Service",
17+
"Database Query Handler",
18+
"File Storage API",
19+
"Email Notification",
20+
"Payment Gateway",
21+
]
22+
23+
data = []
24+
for service in services:
25+
if service == "Authentication Service":
26+
values = np.random.normal(120, 25, 80)
27+
elif service == "Database Query Handler":
28+
values = np.random.normal(85, 40, 80)
29+
values = np.append(values, [220, 250, 280]) # Add outliers
30+
elif service == "File Storage API":
31+
values = np.random.normal(200, 50, 80)
32+
elif service == "Email Notification":
33+
values = np.random.normal(150, 30, 80)
34+
else: # Payment Gateway
35+
values = np.random.normal(180, 60, 80)
36+
values = np.append(values, [350, 380]) # Add outliers
37+
38+
for v in values:
39+
data.append({"Service": service, "Response Time": max(10, v)})
40+
41+
df = pd.DataFrame(data)
42+
43+
# Sort by median response time for easier comparison
44+
medians = df.groupby("Service")["Response Time"].median().sort_values()
45+
df["Service"] = pd.Categorical(df["Service"], categories=medians.index, ordered=True)
46+
47+
# Colors - Python palette
48+
colors = ["#306998", "#FFD43B", "#4B8BBE", "#646464", "#FFE873"]
49+
50+
# Create horizontal box plot using coord_flip()
51+
plot = (
52+
ggplot(df, aes(x="Service", y="Response Time", fill="Service"))
53+
+ geom_boxplot(alpha=0.8, size=0.8, outlier_size=3, outlier_alpha=0.7)
54+
+ coord_flip()
55+
+ scale_fill_manual(values=colors)
56+
+ labs(title="box-horizontal · plotnine · pyplots.ai", x="", y="Response Time (ms)")
57+
+ theme_minimal()
58+
+ theme(
59+
figure_size=(16, 9),
60+
plot_title=element_text(size=24, face="bold"),
61+
axis_title_x=element_text(size=20),
62+
axis_title_y=element_text(size=20),
63+
axis_text_x=element_text(size=16),
64+
axis_text_y=element_text(size=16),
65+
legend_position="none",
66+
panel_grid_major_y=element_text(color="#cccccc"),
67+
)
68+
)
69+
70+
# Save
71+
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: box-horizontal
3+
created: '2025-12-30T09:31:06Z'
4+
updated: '2025-12-30T09:39:06Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20593349974
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/box-horizontal/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/box-horizontal/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent data design with realistic service response time scenario showing varied
17+
distributions and outliers
18+
- Services sorted by median response time as recommended in the spec for easier
19+
comparison
20+
- Clean KISS code structure following plotnine grammar of graphics idiom
21+
- Good visual hierarchy with appropriately sized text elements
22+
- Python-themed color palette adds personality while remaining readable
23+
weaknesses:
24+
- 'Minor code issue: panel_grid_major_y uses element_text() instead of element_line()
25+
which is incorrect'
26+
- Y-axis label is empty string instead of descriptive label like Service Type
27+
- Could use more distinctive plotnine features like faceting or statistical transformations

0 commit comments

Comments
 (0)