{"spec_id":"pyramid-basic","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\npyramid-basic: Basic Pyramid Chart\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 85/100 | Updated: 2026-04-29\n\"\"\"\n\nimport os\nimport sys\n\n\n# Pop script directory so local pygal.py doesn't shadow the installed package\n_script_dir = sys.path.pop(0)\n\nimport pygal\nfrom pygal.style import Style\n\n\nsys.path.insert(0, _script_dir)\n\n# Theme tokens\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# US 2023 population by age group (millions); prime working-age cohorts 30-49 lead both sexes\nage_groups = [\"0-9\", \"10-19\", \"20-29\", \"30-39\", \"40-49\", \"50-59\", \"60-69\", \"70-79\", \"80+\"]\nfemale = [18.0, 20.0, 21.5, 21.8, 21.0, 21.5, 20.0, 14.0, 9.5]\nmale = [18.8, 20.8, 21.8, 22.1, 21.3, 21.0, 19.0, 12.2, 5.8]\n\n# Style — stroke_width=0 removes heavy bar outlines that bleed in dark theme\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_SOFT,\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=0,\n)\n\n# Plot — guides off for a clean look; legend at bottom for better layout\nchart = pygal.Pyramid(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"pyramid-basic · pygal · anyplot.ai\",\n    x_title=\"Population (millions) — 30–49 cohorts at peak for both sexes\",\n    y_title=\"Age Group\",\n    show_y_guides=False,\n    show_x_guides=False,\n    print_values=False,\n    show_legend=True,\n    human_readable=True,\n    legend_at_bottom=True,\n    legend_at_bottom_columns=2,\n)\n\nchart.x_labels = age_groups\n\n# First series goes RIGHT (female), second goes LEFT (male)\nchart.add(\"Female\", female)\nchart.add(\"Male\", male)\n\n# Save\nchart.render_to_png(f\"plot-{THEME}.png\")\nchart.render_to_file(f\"plot-{THEME}.html\")\n"}