{"spec_id":"bar-error","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nbar-error: Bar Chart with Error Bars\nLibrary: matplotlib 3.11.2 | Python 3.13.15\nQuality: 93/100 | Updated: 2026-09-27\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nBRAND = \"#009E73\"  # Imprint palette position 1\n\n# Data: A/B test results comparing feature variants with confidence intervals\nnp.random.seed(42)\ncategories = [\"Control\", \"Variant A\", \"Variant B\", \"Variant C\", \"Variant D\"]\nvalues = [12.3, 15.8, 14.2, 18.5, 11.7]\nerrors = [1.2, 2.1, 1.5, 2.8, 1.0]\n\ncontrol_value = values[0]\nwinner = int(np.argmax(values))\nlift_pct = round((values[winner] - control_value) / control_value * 100)\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nx = np.arange(len(categories))\nbar_width = 0.6\n\nbars = ax.bar(x, values, bar_width, color=BRAND, edgecolor=INK_SOFT, linewidth=1.2, zorder=2)\n# Focal point: the winning variant gets a bolder outline, everything else stays even-weighted\nbars[winner].set_edgecolor(INK)\nbars[winner].set_linewidth(2.2)\n\nax.errorbar(x, values, yerr=errors, fmt=\"none\", ecolor=INK_SOFT, elinewidth=2.2, capsize=7, capthick=1.8, zorder=3)\n\n# Control baseline reference — lets every variant be read as a lift over Control\nax.axhline(control_value, color=INK_MUTED, linestyle=\"--\", linewidth=1, alpha=0.6, zorder=1)\n\n# Value labels above each error cap\nfor xi, value, error in zip(x, values, errors, strict=True):\n    ax.text(xi, value + error + 0.5, f\"{value:.1f}%\", ha=\"center\", va=\"bottom\", fontsize=9, color=INK_SOFT)\n\n# Labels and styling\nax.set_xlabel(\"Test Group\", fontsize=10, color=INK)\nax.set_ylabel(\"Conversion Rate (%)\", fontsize=10, color=INK)\nax.set_title(\"bar-error · python · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK)\nax.set_xticks(x)\nax.set_xticklabels(categories, fontsize=8, color=INK_SOFT)\nax.tick_params(axis=\"y\", labelsize=8, colors=INK_SOFT)\n\n# Spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\n# Grid\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK, zorder=0)\n\n# Annotation: ties the focal point to the story the error bars tell\nax.annotate(\n    f\"{categories[winner]}: +{lift_pct}% vs Control baseline\\n(error bars: 95% CI)\",\n    xy=(winner, values[winner] + errors[winner]),\n    xytext=(winner - 1.4, values[winner] + errors[winner] + 3.5),\n    fontsize=9,\n    ha=\"left\",\n    va=\"bottom\",\n    color=INK_SOFT,\n    arrowprops={\"arrowstyle\": \"-\", \"color\": INK_SOFT, \"linewidth\": 1},\n    bbox={\"boxstyle\": \"round,pad=0.5\", \"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.9, \"linewidth\": 1},\n)\n\nax.set_ylim(0, max(v + e for v, e in zip(values, errors, strict=True)) * 1.5)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}