{"spec_id":"pie-basic","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\npie-basic: Basic Pie Chart\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-05-28\n\"\"\"\n\nimport os\n\nimport pygal\nfrom pygal.style import Style\n\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_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\nIMPRINT_PALETTE = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\")\n\n# Data — global streaming video platform market share (2024 estimates)\ncategories = [\n    (\"Netflix\", 29.5),\n    (\"Amazon Prime Video\", 22.2),\n    (\"YouTube Premium\", 18.6),\n    (\"Disney+\", 14.1),\n    (\"Apple TV+\", 7.8),\n    (\"Others\", 7.8),\n]\n\ntitle = \"Streaming Video Market · pie-basic · python · pygal · anyplot.ai\"\nn = len(title)\ntitle_font_size = max(44, round(66 * 67 / n)) if n > 67 else 66\n\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_PALETTE,\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    value_colors=(\"#FFFFFF\",) * len(categories),\n    stroke_width=2.5,\n)\n\nchart = pygal.Pie(\n    width=2400,\n    height=2400,\n    style=custom_style,\n    title=title,\n    inner_radius=0,\n    legend_at_bottom=True,\n    legend_at_bottom_columns=3,\n    legend_box_size=36,\n    print_values=True,\n    print_labels=False,\n    print_values_position=\"center\",\n    value_formatter=lambda x: f\"{x:.1f}%\",\n    margin=80,\n    margin_bottom=120,\n    truncate_legend=-1,\n)\n\n# Enriched legend names carry narrative context\nlegend_names = {\"Netflix\": \"Netflix (#1 globally)\", \"Others\": \"Others (combined)\"}\n\nfor service, value in categories:\n    # Theme-adaptive stroke creates a clean gap between slices in both themes\n    slice_data = {\"value\": value, \"style\": f\"stroke: {PAGE_BG}; stroke-width: 4\"}\n    # Explode the largest slice (Netflix) prominently to signal market leadership\n    if service == \"Netflix\":\n        slice_data[\"node\"] = {\"transform\": \"translate(0, -80)\"}\n\n    name = legend_names.get(service, service)\n    chart.add(name, [slice_data])\n\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}