{"spec_id":"bar-error","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nbar-error: Bar Chart with Error Bars\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-05-10\n\"\"\"\n\nimport os\n\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    element_line,\n    element_rect,\n    element_text,\n    geom_col,\n    geom_errorbar,\n    ggplot,\n    labs,\n    theme,\n    theme_minimal,\n)\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nBRAND = \"#009E73\"\n\n# Data - Survey results showing average satisfaction scores with 95% CI\ncategories = [\"Product Quality\", \"Customer Service\", \"Delivery Speed\", \"Price Value\", \"Website UX\", \"Return Policy\"]\nvalues = [4.2, 3.8, 4.5, 3.5, 4.0, 4.3]\nerrors = [0.3, 0.4, 0.2, 0.5, 0.35, 0.25]  # 95% CI half-widths\n\ndf = pd.DataFrame(\n    {\n        \"category\": categories,\n        \"value\": values,\n        \"error_lower\": [v - e for v, e in zip(values, errors, strict=True)],\n        \"error_upper\": [v + e for v, e in zip(values, errors, strict=True)],\n    }\n)\n\n# Preserve category order\ndf[\"category\"] = pd.Categorical(df[\"category\"], categories=categories, ordered=True)\n\n# Plot\nplot = (\n    ggplot(df, aes(x=\"category\", y=\"value\"))\n    + geom_col(fill=BRAND, width=0.7)\n    + geom_errorbar(aes(ymin=\"error_lower\", ymax=\"error_upper\"), width=0.25, size=1.2, color=INK_SOFT)\n    + labs(\n        x=\"Survey Category\",\n        y=\"Satisfaction Score (1-5)\",\n        title=\"bar-error \\u00b7 plotnine \\u00b7 pyplots.ai\",\n        caption=\"Error bars represent 95% CI\",\n    )\n    + theme_minimal()\n    + theme(\n        figure_size=(16, 9),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_border=element_rect(color=INK_SOFT, fill=None, size=0.5),\n        panel_grid_major_x=element_line(alpha=0),\n        panel_grid_minor=element_line(alpha=0),\n        panel_grid_major_y=element_line(color=INK, size=0.3, alpha=0.1),\n        plot_title=element_text(size=24, weight=\"bold\", color=INK),\n        axis_title_x=element_text(size=20, color=INK),\n        axis_title_y=element_text(size=20, color=INK),\n        axis_text_x=element_text(size=14, angle=25, ha=\"right\", color=INK_SOFT),\n        axis_text_y=element_text(size=16, color=INK_SOFT),\n        plot_caption=element_text(size=14, style=\"italic\", color=INK_SOFT),\n        axis_line=element_line(color=INK_SOFT, size=0.5),\n    )\n)\n\n# Save with theme-aware filename\nplot.save(f\"plot-{THEME}.png\", dpi=300, verbose=False)\n"}