Skip to content

Commit 2bfb3e3

Browse files
feat(plotnine): implement errorbar-asymmetric (#2799)
## Implementation: `errorbar-asymmetric` - plotnine Implements the **plotnine** version of `errorbar-asymmetric`. **File:** `plots/errorbar-asymmetric/implementations/plotnine.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20602450102)* --------- 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 71b9b02 commit 2bfb3e3

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
""" pyplots.ai
2+
errorbar-asymmetric: Asymmetric Error Bars Plot
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_errorbar, geom_point, ggplot, labs, theme, theme_minimal
10+
11+
12+
# Data - Quarterly revenue projections with asymmetric confidence intervals
13+
np.random.seed(42)
14+
quarters = ["Q1 2024", "Q2 2024", "Q3 2024", "Q4 2024", "Q1 2025", "Q2 2025"]
15+
central_values = [120, 135, 128, 155, 142, 160]
16+
# Asymmetric intervals: downside risk tends to be larger (conservative projections)
17+
error_lower = [15, 18, 12, 22, 16, 20]
18+
error_upper = [10, 12, 8, 15, 11, 14]
19+
20+
df = pd.DataFrame(
21+
{
22+
"quarter": pd.Categorical(quarters, categories=quarters, ordered=True),
23+
"revenue": central_values,
24+
"ymin": [c - lo for c, lo in zip(central_values, error_lower, strict=True)],
25+
"ymax": [c + up for c, up in zip(central_values, error_upper, strict=True)],
26+
}
27+
)
28+
29+
# Create plot with asymmetric error bars
30+
plot = (
31+
ggplot(df, aes(x="quarter", y="revenue"))
32+
+ geom_errorbar(aes(ymin="ymin", ymax="ymax"), width=0.3, size=1.5, color="#306998")
33+
+ geom_point(size=6, color="#306998")
34+
+ labs(
35+
x="Quarter",
36+
y="Revenue (Million USD)",
37+
title="errorbar-asymmetric · plotnine · pyplots.ai",
38+
caption="Error bars show 10th-90th percentile forecast range",
39+
)
40+
+ theme_minimal()
41+
+ theme(
42+
figure_size=(16, 9),
43+
text=element_text(size=14),
44+
axis_title=element_text(size=20),
45+
axis_text=element_text(size=16),
46+
axis_text_x=element_text(angle=0),
47+
plot_title=element_text(size=24, ha="center"),
48+
plot_caption=element_text(size=14, ha="right"),
49+
panel_grid_major=element_line(alpha=0.3),
50+
panel_grid_minor=element_line(alpha=0.15),
51+
)
52+
)
53+
54+
# Save
55+
plot.save("plot.png", dpi=300)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: plotnine
2+
specification_id: errorbar-asymmetric
3+
created: '2025-12-30T17:48:00Z'
4+
updated: '2025-12-30T17:54:14Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20602450102
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/errorbar-asymmetric/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/errorbar-asymmetric/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent visual clarity with well-sized text and data elements
17+
- Clear demonstration of asymmetric error bars with larger downside risk
18+
- Good use of caption to explain what the error bars represent (as spec recommends)
19+
- Clean, readable code following KISS principles
20+
- Realistic financial forecasting scenario
21+
weaknesses:
22+
- Error bar asymmetry pattern is uniform (all bars have larger downside) - mixing
23+
in some with larger upside would better demonstrate the concept
24+
- 'Grid/legend scoring: caption is good but a proper legend entry could enhance
25+
clarity'

0 commit comments

Comments
 (0)