Skip to content

Commit 964e721

Browse files
feat(letsplot): implement box-horizontal (#2575)
## Implementation: `box-horizontal` - letsplot Implements the **letsplot** version of `box-horizontal`. **File:** `plots/box-horizontal/implementations/letsplot.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20593352038)* --------- 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 5fd49fe commit 964e721

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
""" pyplots.ai
2+
box-horizontal: Horizontal Box Plot
3+
Library: letsplot 4.8.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 lets_plot import *
10+
11+
12+
LetsPlot.setup_html()
13+
14+
# Data - Response times by service type (realistic scenario with varied distributions)
15+
np.random.seed(42)
16+
17+
services = ["API Gateway", "Database Query", "Authentication", "File Storage", "Cache Lookup", "Email Service"]
18+
19+
data = []
20+
# Different distributions to showcase boxplot features (medians, spreads, outliers)
21+
distributions = {
22+
"API Gateway": (120, 40, 3), # Medium response, moderate spread, some outliers
23+
"Database Query": (250, 100, 5), # Slower, high variability, more outliers
24+
"Authentication": (80, 25, 2), # Fast, consistent
25+
"File Storage": (300, 80, 4), # Slowest, variable
26+
"Cache Lookup": (15, 8, 2), # Very fast, tight distribution
27+
"Email Service": (180, 60, 6), # Medium, some outliers
28+
}
29+
30+
for service in services:
31+
mean, std, n_outliers = distributions[service]
32+
# Main distribution
33+
values = np.random.normal(mean, std, 80)
34+
# Add some outliers
35+
outliers = np.random.normal(mean + 4 * std, std / 2, n_outliers)
36+
all_values = np.concatenate([values, outliers])
37+
all_values = np.maximum(all_values, 5) # Ensure positive values
38+
39+
for val in all_values:
40+
data.append({"Service": service, "Response Time (ms)": val})
41+
42+
df = pd.DataFrame(data)
43+
44+
# Create horizontal box plot
45+
plot = (
46+
ggplot(df, aes(x="Response Time (ms)", y="Service"))
47+
+ geom_boxplot(
48+
fill="#306998", color="#1a3a4f", alpha=0.7, outlier_color="#FFD43B", outlier_size=4, outlier_alpha=0.8, size=1.2
49+
)
50+
+ labs(x="Response Time (ms)", y="Service Type", title="box-horizontal · letsplot · pyplots.ai")
51+
+ theme_minimal()
52+
+ theme(
53+
axis_title=element_text(size=20),
54+
axis_text=element_text(size=16),
55+
axis_text_y=element_text(size=16),
56+
plot_title=element_text(size=24),
57+
panel_grid_major_y=element_blank(),
58+
panel_grid_minor=element_blank(),
59+
)
60+
+ ggsize(1600, 900)
61+
)
62+
63+
# Save as PNG (scale 3x to get 4800 x 2700 px)
64+
ggsave(plot, "plot.png", path=".", scale=3)
65+
66+
# Save interactive HTML version
67+
ggsave(plot, "plot.html", path=".")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library: letsplot
2+
specification_id: box-horizontal
3+
created: '2025-12-30T09:31:53Z'
4+
updated: '2025-12-30T09:42:25Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20593352038
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 4.8.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/box-horizontal/letsplot/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/box-horizontal/letsplot/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/box-horizontal/letsplot/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent data design with varied distributions showcasing boxplot features (different
17+
medians, spreads, outliers)
18+
- Clean horizontal orientation with readable service type labels
19+
- Good color contrast between blue boxes and yellow outliers
20+
- Realistic tech scenario with appropriate response time values
21+
- Proper title format and axis labels with units
22+
weaknesses:
23+
- Grid lines could be more subtle (alpha reduced) for better visual balance
24+
- Does not leverage lets-plot distinctive features like interactive tooltips or
25+
hover information
26+
- Minor empty space on right side of plot due to outlier distribution

0 commit comments

Comments
 (0)