diff --git a/plots/bar-error/implementations/seaborn.py b/plots/bar-error/implementations/seaborn.py new file mode 100644 index 0000000000..bd89657add --- /dev/null +++ b/plots/bar-error/implementations/seaborn.py @@ -0,0 +1,83 @@ +""" pyplots.ai +bar-error: Bar Chart with Error Bars +Library: seaborn 0.13.2 | Python 3.13.11 +Quality: 91/100 | Created: 2025-12-27 +""" + +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd +import seaborn as sns + + +# Data - A/B test results with confidence intervals +np.random.seed(42) + +categories = ["Control", "Variant A", "Variant B", "Variant C", "Variant D", "Variant E"] +# Conversion rates (percentage) +values = [4.2, 5.1, 4.8, 6.3, 5.5, 4.0] +# 95% CI error margins (asymmetric for realistic percentage data) +errors_lower = [0.3, 0.4, 0.35, 0.5, 0.45, 0.25] +errors_upper = [0.35, 0.45, 0.4, 0.55, 0.5, 0.3] + +df = pd.DataFrame( + {"Category": categories, "Conversion Rate (%)": values, "Error Lower": errors_lower, "Error Upper": errors_upper} +) + +# Create figure +fig, ax = plt.subplots(figsize=(16, 9)) + +# Create bar plot using seaborn +colors = ["#306998", "#FFD43B", "#306998", "#FFD43B", "#306998", "#FFD43B"] +sns.barplot( + data=df, + x="Category", + y="Conversion Rate (%)", + hue="Category", + palette=colors, + legend=False, + ax=ax, + edgecolor="black", + linewidth=1.5, + width=0.7, +) + +# Add error bars with caps +x_positions = np.arange(len(categories)) +ax.errorbar( + x_positions, + values, + yerr=[errors_lower, errors_upper], + fmt="none", + ecolor="black", + elinewidth=2.5, + capsize=12, + capthick=2.5, +) + +# Styling for large canvas (4800x2700 px at dpi=300) +ax.set_xlabel("Test Group", fontsize=20) +ax.set_ylabel("Conversion Rate (%)", fontsize=20) +ax.set_title("bar-error · seaborn · pyplots.ai", fontsize=24, fontweight="bold") +ax.tick_params(axis="both", labelsize=16) + +# Add annotation explaining error bars +ax.annotate( + "Error bars: 95% CI", + xy=(0.98, 0.95), + xycoords="axes fraction", + fontsize=14, + ha="right", + va="top", + bbox={"boxstyle": "round,pad=0.3", "facecolor": "white", "edgecolor": "gray", "alpha": 0.8}, +) + +# Subtle grid +ax.yaxis.grid(True, alpha=0.3, linestyle="--") +ax.set_axisbelow(True) + +# Set y-axis to start from 0 for proper bar comparison +ax.set_ylim(0, max(values) * 1.25) + +plt.tight_layout() +plt.savefig("plot.png", dpi=300, bbox_inches="tight") diff --git a/plots/bar-error/metadata/seaborn.yaml b/plots/bar-error/metadata/seaborn.yaml new file mode 100644 index 0000000000..5b3488f9c4 --- /dev/null +++ b/plots/bar-error/metadata/seaborn.yaml @@ -0,0 +1,29 @@ +library: seaborn +specification_id: bar-error +created: '2025-12-27T19:21:22Z' +updated: '2025-12-27T19:29:06Z' +generated_by: claude-opus-4-5-20251101 +workflow_run: 20543280392 +issue: 0 +python_version: 3.13.11 +library_version: 0.13.2 +preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-error/seaborn/plot.png +preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-error/seaborn/plot_thumb.png +preview_html: null +quality_score: 91 +review: + strengths: + - Excellent text sizing following the 24/20/16pt guideline for large canvas + - Clean alternating color scheme that is colorblind-accessible + - Proper use of asymmetric error bars for percentage data as spec suggests + - Good annotation explaining what error bars represent (95% CI) + - Modern seaborn API usage with hue parameter to avoid deprecation warnings + - Y-axis correctly starts at 0 for proper bar comparison + - Realistic A/B testing scenario with plausible conversion rate values + weaknesses: + - Error bars added via matplotlib errorbar() rather than exploring seaborn native + statistical capabilities + - The annotation box could be positioned closer to the data area rather than isolated + in the corner + - Feature coverage could show more variation (e.g., one notably different group + or wider CI range)