{"spec_id":"bar-error","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nbar-error: Bar Chart with Error Bars\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 81/100 | Updated: 2026-05-10\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport plotly.graph_objects as go\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Data - Lab experiment comparing treatment effectiveness\nnp.random.seed(42)\ncategories = [\"Control\", \"Treatment A\", \"Treatment B\", \"Treatment C\", \"Treatment D\"]\nvalues = np.array([45.2, 62.8, 58.3, 71.5, 55.9])\n# Asymmetric errors with more dramatic variation across groups\nerrors_lower = np.array([3.2, 7.8, 2.9, 8.1, 3.5])\nerrors_upper = np.array([4.1, 9.2, 3.6, 11.3, 4.8])\n\n# Create figure\nfig = go.Figure()\n\nfig.add_trace(\n    go.Bar(\n        x=categories,\n        y=values,\n        marker=dict(color=BRAND, line=dict(color=INK_SOFT, width=2)),\n        error_y=dict(\n            type=\"data\",\n            symmetric=False,\n            array=errors_upper,\n            arrayminus=errors_lower,\n            color=INK_SOFT,\n            thickness=3,\n            width=12,\n        ),\n        name=\"Measurement\",\n        hovertemplate=\"<b>%{x}</b><br>Value: %{y:.1f}%<br>+%{error_y.array[0]:.1f}% / -%{error_y.arrayminus[0]:.1f}%<extra></extra>\",\n    )\n)\n\n# Layout for 4800x2700 px output\nfig.update_layout(\n    title=dict(text=\"bar-error · plotly · anyplot.ai\", font=dict(size=28, color=INK), x=0.5, xanchor=\"center\"),\n    xaxis=dict(\n        title=dict(text=\"Treatment Group\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        showgrid=False,\n        linecolor=INK_SOFT,\n        linewidth=1,\n    ),\n    yaxis=dict(\n        title=dict(text=\"Response Value (%)\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        gridcolor=GRID,\n        gridwidth=1,\n        linecolor=INK_SOFT,\n        linewidth=1,\n        range=[0, 90],\n    ),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font=dict(color=INK),\n    showlegend=True,\n    legend=dict(\n        x=0.98, y=0.98, bgcolor=ELEVATED_BG, bordercolor=INK_SOFT, borderwidth=1, font=dict(size=16, color=INK_SOFT)\n    ),\n    margin=dict(l=100, r=80, t=120, b=100),\n    annotations=[\n        dict(\n            text=\"Error bars: ±1 SD (asymmetric)\",\n            xref=\"paper\",\n            yref=\"paper\",\n            x=0.02,\n            y=0.02,\n            xanchor=\"left\",\n            yanchor=\"bottom\",\n            font=dict(size=14, color=INK_SOFT),\n            showarrow=False,\n        )\n    ],\n)\n\n# Save as PNG (4800x2700 px) and HTML\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}