{"spec_id":"box-horizontal","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nbox-horizontal: Horizontal Box Plot\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 83/100 | Updated: 2026-05-12\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pygal\nfrom pygal.style import Style\n\n\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\"\n\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\")\n\n# Data - Salary ranges by job title\nnp.random.seed(42)\ncategories = [\"Software Engineer\", \"Data Scientist\", \"Product Manager\", \"Designer\", \"DevOps Engineer\"]\ndata = {\n    \"Software Engineer\": np.random.normal(125000, 20000, 100),\n    \"Data Scientist\": np.random.normal(130000, 22000, 100),\n    \"Product Manager\": np.random.normal(140000, 25000, 100),\n    \"Designer\": np.random.normal(105000, 18000, 100),\n    \"DevOps Engineer\": np.random.normal(135000, 21000, 100),\n}\n\n# Custom style using theme-adaptive tokens\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=IMPRINT,\n    title_font_size=28,\n    label_font_size=22,\n    major_label_font_size=18,\n    legend_font_size=16,\n    value_font_size=14,\n    stroke_width=3,\n)\n\n# Create horizontal box dynamically (pygal doesn't include HorizontalBox natively)\nHorizontalBox = type(\"HorizontalBox\", (pygal.graph.horizontal.HorizontalGraph, pygal.graph.box.Box), {})\n\n# Create chart\nchart = HorizontalBox(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"box-horizontal · pygal · anyplot.ai\",\n    x_title=\"Salary (USD)\",\n    show_legend=True,\n    show_y_guides=True,\n    show_x_guides=False,\n    margin=80,\n    margin_left=300,\n    margin_bottom=120,\n    box_mode=\"tukey\",\n)\n\n# Set category labels on y-axis\nchart.x_labels = categories\n\n# Add data for each category\nfor category in categories:\n    chart.add(category, data[category].tolist())\n\n# Save outputs\nchart.render_to_file(f\"plot-{THEME}.html\")\nchart.render_to_png(f\"plot-{THEME}.png\")\n"}