{"spec_id":"errorbar-basic","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nerrorbar-basic: Basic Error Bar Plot\nLibrary: plotnine 0.15.7 | Python 3.13.14\nQuality: 84/100 | Updated: 2026-06-30\n\"\"\"\n\nimport os\n\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    element_blank,\n    element_line,\n    element_rect,\n    element_text,\n    geom_crossbar,\n    ggplot,\n    labs,\n    position_dodge,\n    scale_color_manual,\n    scale_fill_manual,\n    scale_x_discrete,\n    theme,\n    theme_minimal,\n)\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\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\n# Data — three analytical methods measuring nitrate concentration across six sampling sites\ndata = pd.DataFrame(\n    {\n        \"site\": [\"Site A\", \"Site B\", \"Site C\", \"Site D\", \"Site E\", \"Site F\"] * 3,\n        \"method\": [\"Standard\"] * 6 + [\"Enhanced\"] * 6 + [\"Automated\"] * 6,\n        \"concentration\": [\n            # Standard: baseline sensitivity, tight precision\n            36.2,\n            39.8,\n            42.1,\n            37.5,\n            43.6,\n            40.4,\n            # Enhanced: ~35% higher detection\n            48.5,\n            52.3,\n            55.7,\n            49.2,\n            56.1,\n            51.8,\n            # Automated: highest values, greatest variability\n            61.4,\n            65.8,\n            69.2,\n            58.6,\n            67.3,\n            63.5,\n        ],\n        \"se\": [\n            1.8,\n            2.1,\n            1.6,\n            2.3,\n            1.9,\n            2.0,  # Standard: SE ±1.6–2.3\n            3.2,\n            2.8,\n            3.5,\n            3.0,\n            2.6,\n            3.4,  # Enhanced: SE ±2.6–3.5\n            5.1,\n            6.3,\n            4.8,\n            7.2,\n            5.5,\n            6.0,  # Automated: SE ±4.8–7.2\n        ],\n    }\n)\n\ndata[\"ymin\"] = data[\"concentration\"] - data[\"se\"]\ndata[\"ymax\"] = data[\"concentration\"] + data[\"se\"]\n\n# Sort sites by Standard-method concentration so all three methods trend upward left→right\nsite_order = data[data[\"method\"] == \"Standard\"].set_index(\"site\")[\"concentration\"].sort_values().index.tolist()\n\ndodge = position_dodge(width=0.6)\n\ntitle = \"errorbar-basic · python · plotnine · anyplot.ai\"\nsubtitle = \"Automated sampling shows 3–4× wider uncertainty than Standard across all sites\"\n\nplot = (\n    ggplot(data, aes(x=\"site\", y=\"concentration\", color=\"method\", fill=\"method\", group=\"method\"))\n    + geom_crossbar(aes(ymin=\"ymin\", ymax=\"ymax\"), width=0.18, fatten=3, size=0.9, alpha=0.2, position=dodge)\n    + scale_color_manual(values=IMPRINT, name=\"Method\")\n    + scale_fill_manual(values=IMPRINT, name=\"Method\")\n    + scale_x_discrete(limits=site_order)\n    + labs(x=\"Sampling Site\", y=\"Nitrate Concentration (mg/L)\", title=title, subtitle=subtitle)\n    + theme_minimal()\n    + theme(\n        figure_size=(8, 4.5),\n        text=element_text(size=7, color=INK_SOFT),\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_blank(),\n        panel_grid_major_x=element_blank(),\n        panel_grid_minor=element_blank(),\n        panel_grid_major_y=element_line(color=INK, size=0.3, alpha=0.10),\n        axis_line_x=element_line(color=INK_SOFT, size=0.6),\n        axis_line_y=element_blank(),\n        axis_ticks=element_blank(),\n        axis_title=element_text(size=10, color=INK),\n        axis_text=element_text(size=8, color=INK_SOFT),\n        plot_title=element_text(size=12, color=INK, weight=\"bold\"),\n        plot_subtitle=element_text(size=9, color=INK_MUTED),\n        legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT, size=0.4),\n        legend_key=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        legend_text=element_text(size=8, color=INK_SOFT),\n        legend_title=element_text(size=8, color=INK),\n        legend_position=\"right\",\n    )\n)\n\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=8, height=4.5, units=\"in\", verbose=False)\n"}