{"spec_id":"bar-horizontal","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nbar-horizontal: Horizontal Bar Chart\nLibrary: pygal 3.1.3 | Python 3.13.14\nQuality: 90/100 | Updated: 2026-08-05\n\"\"\"\n\nimport os\n\nimport pygal\nfrom pygal.style import Style\n\n\n# Theme tokens (Imprint palette)\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nBRAND = \"#009E73\"  # Imprint palette position 1\n\n# Data - Retail revenue by product category (sorted descending for ranking display)\ncategories = [\n    \"Electronics\",\n    \"Apparel\",\n    \"Home & Furniture\",\n    \"Groceries\",\n    \"Health & Beauty\",\n    \"Sporting Goods\",\n    \"Toys & Games\",\n    \"Books & Media\",\n    \"Automotive\",\n    \"Garden & Outdoor\",\n]\nvalues = [842.6, 615.3, 498.7, 437.2, 356.8, 289.4, 214.5, 156.9, 128.3, 97.6]\n\n# Title fontsize scales with title length (formula: prompts/plot-generator.md)\nTITLE = \"Retail Revenue by Category · bar-horizontal · python · pygal · anyplot.ai\"\n_ratio = 67 / len(TITLE) if len(TITLE) > 67 else 1.0\ntitle_font_size = max(44, round(66 * _ratio))\n\n# Custom style with theme-adaptive colors, sized for the 3200x1800 canvas\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_MUTED,\n    colors=(BRAND,),\n    title_font_size=title_font_size,\n    label_font_size=56,\n    major_label_font_size=44,\n    legend_font_size=44,\n    value_font_size=36,\n    stroke_width=2.5,\n    opacity=\"1\",\n    opacity_hover=\"1\",\n)\n\n# Create horizontal bar chart - ultra-minimal, no x-axis guides\nchart = pygal.HorizontalBar(\n    width=3200,\n    height=1800,\n    style=custom_style,\n    title=TITLE,\n    x_title=\"Revenue ($M)\",\n    show_legend=False,\n    show_y_guides=False,\n    show_x_guides=False,\n    spacing=20,\n    margin=40,\n    margin_left=280,\n    margin_right=140,\n    margin_top=100,\n    margin_bottom=100,\n    print_values=True,\n    print_values_position=\"end\",\n    value_formatter=lambda x: f\"${x:,.1f}M\",\n    truncate_label=-1,\n)\n\n# Add data as single series. pygal.HorizontalBar transposes axes internally,\n# so x_labels carries the category axis and y_labels the value-tick axis.\nchart.add(\"Revenue\", values)\nchart.x_labels = categories\nchart.y_labels = [str(v) for v in range(0, 901, 150)]\n\n# Save outputs\nchart.render_to_png(f\"plot-{THEME}.png\")\nchart.render_to_file(f\"plot-{THEME}.html\")\n"}