{"spec_id":"bar-error","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nbar-error: Bar Chart with Error Bars\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-05-10\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\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\"\n\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Set theme\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.10,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Data - Medical trial: treatment effects on symptom relief (%)\nnp.random.seed(42)\ncategories = [\"Placebo\", \"Low Dose\", \"Medium Dose\", \"High Dose\", \"Combined\"]\nvalues = [25.3, 42.1, 58.7, 71.2, 68.4]\nerrors = [4.2, 5.1, 6.3, 5.8, 6.9]  # Standard deviations (±1 SD)\n\ndf = pd.DataFrame({\"Treatment\": categories, \"Relief (%)\": values, \"Std Dev\": errors})\n\n# Create figure and plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\n\n# Bar plot with error bars\nsns.barplot(data=df, x=\"Treatment\", y=\"Relief (%)\", color=BRAND, ax=ax, edgecolor=INK_SOFT, linewidth=1.5, width=0.6)\n\n# Add error bars with caps\nx_positions = np.arange(len(categories))\nax.errorbar(x_positions, values, yerr=errors, fmt=\"none\", ecolor=INK_SOFT, elinewidth=2.5, capsize=10, capthick=2.5)\n\n# Labels and title\nax.set_xlabel(\"Treatment Group\", fontsize=20, color=INK)\nax.set_ylabel(\"Symptom Relief (%)\", fontsize=20, color=INK)\nax.set_title(\"bar-error · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Grid (y-axis only)\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8)\nax.set_axisbelow(True)\n\n# Remove top and right 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# Set y-axis limits\nax.set_ylim(0, 85)\n\n# Add annotation explaining error bars\nax.text(\n    0.98,\n    0.95,\n    \"Error bars: ±1 SD\",\n    transform=ax.transAxes,\n    fontsize=14,\n    color=INK_SOFT,\n    ha=\"right\",\n    va=\"top\",\n    bbox={\"boxstyle\": \"round,pad=0.5\", \"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"linewidth\": 0.8, \"alpha\": 0.9},\n)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}