{"spec_id":"bar-horizontal","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nbar-horizontal: Horizontal Bar Chart\nLibrary: letsplot 4.11.0 | Python 3.13.14\nQuality: 91/100 | Updated: 2026-08-05\n\"\"\"\n\nimport os\n\nimport pandas as pd\nfrom lets_plot import *\n\n\nLetsPlot.setup_html()\n\n# Theme tokens (see prompts/default-style-guide.md \"Background\" + \"Theme-adaptive Chrome\")\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\"\nRULE = \"rgba(26,26,23,0.15)\" if THEME == \"light\" else \"rgba(240,239,232,0.15)\"\nBRAND = \"#009E73\"  # Imprint palette position 1 — ALWAYS first series\nHIGHLIGHT = \"#4467A3\"  # Imprint palette position 3 — draws the eye to the leader\n\n# Data - programming language popularity survey (sorted ascending for easy ranking)\ndata = pd.DataFrame(\n    {\n        \"language\": [\"Rust\", \"Go\", \"C\", \"PHP\", \"C++\", \"C#\", \"TypeScript\", \"Java\", \"Python\", \"JavaScript\"],\n        \"developers\": [11.76, 13.24, 19.34, 20.87, 22.55, 29.81, 34.83, 35.35, 49.28, 65.36],\n    }\n)\ndata[\"language\"] = pd.Categorical(data[\"language\"], categories=data[\"language\"].tolist(), ordered=True)\ndata[\"is_leader\"] = data[\"language\"] == data.loc[data[\"developers\"].idxmax(), \"language\"]\ndata[\"value_label\"] = data[\"developers\"].map(lambda v: f\"{v:.1f}%\")\n\n# Plot — single-color bars with the top language highlighted, value labels at bar ends\n# tooltips: lets-plot-distinctive interactive labels surfaced in the HTML export\nbar_tooltips = layer_tooltips().line(\"@language\").line(\"@value_label\")\n\nplot = (\n    ggplot(data, aes(x=\"developers\", y=\"language\", fill=\"is_leader\"))\n    + geom_bar(stat=\"identity\", width=0.65, alpha=0.9, show_legend=False, color=PAGE_BG, tooltips=bar_tooltips)\n    + geom_text(aes(label=\"value_label\"), hjust=\"left\", nudge_x=1.5, size=4.2, color=INK_SOFT)\n    + scale_fill_manual(values=[BRAND, HIGHLIGHT])\n    + scale_x_continuous(limits=[0, 75], expand=[0, 0])\n    + labs(\n        x=\"Developers Using Language (%)\",\n        y=\"Programming Language\",\n        title=\"bar-horizontal · python · letsplot · anyplot.ai\",\n        subtitle=\"JavaScript leads adoption, used by more than 5x as many developers as Rust\",\n    )\n    + ggsize(800, 450)\n    + theme(\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_grid_major_x=element_line(color=RULE, size=0.3),\n        panel_grid_major_y=element_blank(),\n        panel_grid_minor=element_blank(),\n        axis_title_x=element_text(size=12, color=INK),\n        axis_title_y=element_text(size=12, color=INK),\n        axis_text_x=element_text(size=10, color=INK_SOFT),\n        axis_text_y=element_text(size=10, color=INK_SOFT),\n        axis_line=element_blank(),\n        axis_ticks=element_blank(),\n        plot_title=element_text(size=19, color=INK),\n        plot_subtitle=element_text(size=11, color=INK_SOFT),\n        legend_position=\"none\",\n    )\n)\n\n# Save as PNG (scale 4x for 3200 x 1800 px) and HTML for interactivity\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", scale=4)\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}