Skip to content

Commit 90f30b8

Browse files
feat(matplotlib): implement bar-error (#2391)
## Implementation: `bar-error` - matplotlib Implements the **matplotlib** version of `bar-error`. **File:** `plots/bar-error/implementations/matplotlib.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20543280641)* --------- 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 b29f40e commit 90f30b8

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
""" pyplots.ai
2+
bar-error: Bar Chart with Error Bars
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-27
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
11+
# Data: A/B test results comparing feature variants with confidence intervals
12+
np.random.seed(42)
13+
categories = ["Control", "Variant A", "Variant B", "Variant C", "Variant D"]
14+
values = [12.3, 15.8, 14.2, 18.5, 11.7] # Conversion rates (%)
15+
errors = [1.2, 2.1, 1.5, 2.8, 1.0] # 95% CI half-widths
16+
17+
# Create figure
18+
fig, ax = plt.subplots(figsize=(16, 9))
19+
20+
# Bar positions
21+
x = np.arange(len(categories))
22+
bar_width = 0.6
23+
24+
# Plot bars with error bars
25+
bars = ax.bar(x, values, bar_width, color="#306998", edgecolor="#1e4466", linewidth=2)
26+
ax.errorbar(x, values, yerr=errors, fmt="none", ecolor="#1e4466", elinewidth=3, capsize=10, capthick=3)
27+
28+
# Labels and styling
29+
ax.set_xlabel("Test Group", fontsize=20)
30+
ax.set_ylabel("Conversion Rate (%)", fontsize=20)
31+
ax.set_title("bar-error · matplotlib · pyplots.ai", fontsize=24)
32+
ax.set_xticks(x)
33+
ax.set_xticklabels(categories, fontsize=16)
34+
ax.tick_params(axis="y", labelsize=16)
35+
36+
# Add annotation explaining error bars
37+
ax.annotate(
38+
"Error bars: 95% CI",
39+
xy=(0.98, 0.02),
40+
xycoords="axes fraction",
41+
fontsize=14,
42+
ha="right",
43+
va="bottom",
44+
bbox={"boxstyle": "round,pad=0.3", "facecolor": "white", "edgecolor": "gray", "alpha": 0.8},
45+
)
46+
47+
# Grid and layout
48+
ax.grid(True, axis="y", alpha=0.3, linestyle="--")
49+
ax.set_ylim(0, max(values) * 1.3)
50+
51+
plt.tight_layout()
52+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library: matplotlib
2+
specification_id: bar-error
3+
created: '2025-12-27T19:21:04Z'
4+
updated: '2025-12-27T19:26:22Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20543280641
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-error/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-error/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent text legibility with appropriate font sizes for all elements
17+
- Clear, realistic A/B test scenario with plausible conversion rate data
18+
- Error bar caps are clearly visible with good sizing (capsize=10, capthick=3)
19+
- Clean annotation explaining what error bars represent (95% CI requirement from
20+
spec)
21+
- Good color choice with consistent dark blue theme
22+
- KISS code structure following matplotlib best practices
23+
weaknesses:
24+
- Error bars are all symmetric; demonstrating asymmetric errors would better showcase
25+
the plot type capabilities
26+
- Annotation box placement in bottom-right corner floats in empty space rather than
27+
being more integrated with the plot
28+
- Basic library usage without leveraging advanced matplotlib features like bar_label()
29+
for showing values

0 commit comments

Comments
 (0)