{"spec_id":"errorbar-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nerrorbar-basic: Basic Error Bar Plot\nLibrary: seaborn 0.13.2 | Python 3.13.14\nQuality: 88/100 | Updated: 2026-06-30\n\"\"\"\n\nimport os\n\nimport matplotlib.patches as mpatches\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\n\n\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\"\n\n# Imprint palette\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\"]\nBRAND = IMPRINT[0]\nACCENT = IMPRINT[1]\n\n# Clinical trial: symptom reduction (%) by dose group (n=30 per group)\nnp.random.seed(42)\ncategories = [\"Control\", \"Placebo\", \"10 mg\", \"25 mg\", \"50 mg\", \"100 mg\"]\nmeans = [45.2, 46.8, 52.3, 57.4, 61.3, 58.9]\nstds = [4.5, 5.1, 6.2, 4.9, 5.8, 7.1]\nn_per_group = 30\n\nrecords = [\n    {\"Dose\": cat, \"Symptom Reduction (%)\": value}\n    for cat, mu, sigma in zip(categories, means, stds, strict=True)\n    for value in np.random.normal(mu, sigma, n_per_group)\n]\ndf = pd.DataFrame(records)\n\ntop_performer = categories[int(np.argmax(means))]\npalette = {c: (ACCENT if c == top_performer else BRAND) for c in categories}\n\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.15,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400)\n\nsns.barplot(\n    data=df,\n    x=\"Dose\",\n    y=\"Symptom Reduction (%)\",\n    hue=\"Dose\",\n    palette=palette,\n    legend=False,\n    errorbar=\"sd\",\n    capsize=0.25,\n    err_kws={\"color\": INK, \"linewidth\": 1.5},\n    edgecolor=INK_SOFT,\n    linewidth=0.6,\n    ax=ax,\n)\n\nax.set_xlabel(\"Dose Group\", fontsize=10)\nax.set_ylabel(\"Symptom Reduction (%)\", fontsize=10)\nax.tick_params(axis=\"both\", labelsize=8)\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8)\nax.xaxis.grid(False)\nax.set_axisbelow(True)\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\n\n# Legend explaining the two-color strategy: all groups vs. top performer\nbrand_patch = mpatches.Patch(color=BRAND, label=\"Dose group\")\naccent_patch = mpatches.Patch(color=ACCENT, label=f\"Top performer ({top_performer})\")\nax.legend(handles=[brand_patch, accent_patch], fontsize=8, framealpha=0.9, loc=\"lower right\")\n\n# Title and subtitle placed in figure coordinates to control vertical spacing precisely\nfig.text(\n    0.5,\n    0.96,\n    \"errorbar-basic · python · seaborn · anyplot.ai\",\n    ha=\"center\",\n    va=\"top\",\n    fontsize=12,\n    fontweight=\"medium\",\n    color=INK,\n)\nfig.text(\n    0.5,\n    0.90,\n    f\"Bars show mean ± 1 SD — {top_performer} achieves the highest mean symptom reduction\",\n    ha=\"center\",\n    va=\"top\",\n    fontsize=9,\n    color=INK_MUTED,\n)\n\nfig.subplots_adjust(top=0.81, bottom=0.13, left=0.11, right=0.97)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}