Skip to content

Commit 24fd704

Browse files
feat(seaborn): implement bar-error (#2396)
## Implementation: `bar-error` - seaborn Implements the **seaborn** version of `bar-error`. **File:** `plots/bar-error/implementations/seaborn.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20543280392)* --------- 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 0037242 commit 24fd704

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
""" pyplots.ai
2+
bar-error: Bar Chart with Error Bars
3+
Library: seaborn 0.13.2 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-27
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import pandas as pd
10+
import seaborn as sns
11+
12+
13+
# Data - A/B test results with confidence intervals
14+
np.random.seed(42)
15+
16+
categories = ["Control", "Variant A", "Variant B", "Variant C", "Variant D", "Variant E"]
17+
# Conversion rates (percentage)
18+
values = [4.2, 5.1, 4.8, 6.3, 5.5, 4.0]
19+
# 95% CI error margins (asymmetric for realistic percentage data)
20+
errors_lower = [0.3, 0.4, 0.35, 0.5, 0.45, 0.25]
21+
errors_upper = [0.35, 0.45, 0.4, 0.55, 0.5, 0.3]
22+
23+
df = pd.DataFrame(
24+
{"Category": categories, "Conversion Rate (%)": values, "Error Lower": errors_lower, "Error Upper": errors_upper}
25+
)
26+
27+
# Create figure
28+
fig, ax = plt.subplots(figsize=(16, 9))
29+
30+
# Create bar plot using seaborn
31+
colors = ["#306998", "#FFD43B", "#306998", "#FFD43B", "#306998", "#FFD43B"]
32+
sns.barplot(
33+
data=df,
34+
x="Category",
35+
y="Conversion Rate (%)",
36+
hue="Category",
37+
palette=colors,
38+
legend=False,
39+
ax=ax,
40+
edgecolor="black",
41+
linewidth=1.5,
42+
width=0.7,
43+
)
44+
45+
# Add error bars with caps
46+
x_positions = np.arange(len(categories))
47+
ax.errorbar(
48+
x_positions,
49+
values,
50+
yerr=[errors_lower, errors_upper],
51+
fmt="none",
52+
ecolor="black",
53+
elinewidth=2.5,
54+
capsize=12,
55+
capthick=2.5,
56+
)
57+
58+
# Styling for large canvas (4800x2700 px at dpi=300)
59+
ax.set_xlabel("Test Group", fontsize=20)
60+
ax.set_ylabel("Conversion Rate (%)", fontsize=20)
61+
ax.set_title("bar-error · seaborn · pyplots.ai", fontsize=24, fontweight="bold")
62+
ax.tick_params(axis="both", labelsize=16)
63+
64+
# Add annotation explaining error bars
65+
ax.annotate(
66+
"Error bars: 95% CI",
67+
xy=(0.98, 0.95),
68+
xycoords="axes fraction",
69+
fontsize=14,
70+
ha="right",
71+
va="top",
72+
bbox={"boxstyle": "round,pad=0.3", "facecolor": "white", "edgecolor": "gray", "alpha": 0.8},
73+
)
74+
75+
# Subtle grid
76+
ax.yaxis.grid(True, alpha=0.3, linestyle="--")
77+
ax.set_axisbelow(True)
78+
79+
# Set y-axis to start from 0 for proper bar comparison
80+
ax.set_ylim(0, max(values) * 1.25)
81+
82+
plt.tight_layout()
83+
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: seaborn
2+
specification_id: bar-error
3+
created: '2025-12-27T19:21:22Z'
4+
updated: '2025-12-27T19:29:06Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20543280392
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.13.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-error/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-error/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent text sizing following the 24/20/16pt guideline for large canvas
17+
- Clean alternating color scheme that is colorblind-accessible
18+
- Proper use of asymmetric error bars for percentage data as spec suggests
19+
- Good annotation explaining what error bars represent (95% CI)
20+
- Modern seaborn API usage with hue parameter to avoid deprecation warnings
21+
- Y-axis correctly starts at 0 for proper bar comparison
22+
- Realistic A/B testing scenario with plausible conversion rate values
23+
weaknesses:
24+
- Error bars added via matplotlib errorbar() rather than exploring seaborn native
25+
statistical capabilities
26+
- The annotation box could be positioned closer to the data area rather than isolated
27+
in the corner
28+
- Feature coverage could show more variation (e.g., one notably different group
29+
or wider CI range)

0 commit comments

Comments
 (0)