{"spec_id":"bar-horizontal","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nbar-horizontal: Horizontal Bar Chart\nLibrary: plotly 6.9.0 | Python 3.13.14\nQuality: 93/100 | Updated: 2026-08-05\n\"\"\"\n\nimport os\n\nimport plotly.graph_objects as go\n\n\n# Theme tokens (see prompts/default-style-guide.md \"Theme-adaptive Chrome\")\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\"\nBRAND = \"#009E73\"  # Imprint palette position 1 — the leading category\n\n# Data - Survey results: \"What programming language do you use most?\"\ncategories = [\"Python\", \"JavaScript\", \"TypeScript\", \"Java\", \"C++\", \"Go\", \"Rust\", \"Ruby\", \"PHP\", \"Swift\"]\nvalues = [2847, 2156, 1823, 1542, 987, 756, 623, 412, 389, 298]\ntotal_responses = sum(values)\n\n# Emphasize the leading language, mute the rest — \"highlight specific bars to\n# draw attention\" per the spec's own guidance, using the muted semantic\n# anchor for the \"rest\" role instead of diluting the categorical palette.\nbar_colors = [BRAND if i == 0 else INK_MUTED for i in range(len(categories))]\n\n# Plot — see default-style-guide.md \"Visual Sizing Defaults\" for the canvas + sizing values\nfig = go.Figure()\nfig.add_trace(\n    go.Bar(\n        y=categories,\n        x=values,\n        orientation=\"h\",\n        marker={\"color\": bar_colors, \"line\": {\"color\": PAGE_BG, \"width\": 1}},\n        texttemplate=\"%{x:,}\",\n        textposition=\"outside\",\n        textfont={\"size\": 12, \"color\": INK_SOFT},\n        cliponaxis=False,\n        hovertemplate=\"<b>%{y}</b><br>%{x:,} responses<extra></extra>\",\n    )\n)\n\n# Style — title kept at the default 16px since the mandated title is only\n# 45 chars (well under the 67-char baseline the sizing table is tuned for)\nfig.update_layout(\n    autosize=False,\n    width=800,\n    height=450,\n    margin={\"l\": 140, \"r\": 50, \"t\": 110, \"b\": 70},\n    title={\n        \"text\": \"bar-horizontal · python · plotly · anyplot.ai\",\n        \"font\": {\"size\": 16, \"color\": INK},\n        \"subtitle\": {\"text\": f\"n = {total_responses:,} survey respondents\", \"font\": {\"size\": 11, \"color\": INK_SOFT}},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n    },\n    xaxis={\n        \"title\": {\"text\": \"Number of Responses\", \"font\": {\"size\": 12, \"color\": INK}},\n        \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n        \"showgrid\": False,\n        \"showline\": True,\n        \"linecolor\": INK_SOFT,\n        \"zerolinecolor\": INK_SOFT,\n        \"range\": [0, max(values) * 1.12],\n    },\n    yaxis={\n        \"title\": {\"text\": \"Programming Language\", \"font\": {\"size\": 12, \"color\": INK}},\n        \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n        \"autorange\": \"reversed\",\n        \"showgrid\": False,\n        \"showline\": True,\n        \"linecolor\": INK_SOFT,\n    },\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK},\n    bargap=0.3,\n    showlegend=False,\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=800, height=450, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}