{"spec_id":"donut-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\ndonut-basic: Basic Donut Chart\nLibrary: plotly 6.8.0 | Python 3.13.14\nQuality: 91/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport plotly.graph_objects as go\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Imprint categorical palette — 8 hues, hybrid-v3 sort\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"]\n\n# Data — FY2026 corporate budget allocation ($100M total)\ncategories = [\"Engineering\", \"Sales\", \"Marketing\", \"Operations\", \"R&D\", \"G&A\"]\nvalues = [42, 24, 14, 10, 6, 4]\ntotal = sum(values)\ncolors = IMPRINT_PALETTE[: len(categories)]\n\n# Pull dominant Engineering segment outward for visual emphasis\npull = [0.05] + [0] * (len(categories) - 1)\n\n# Plot\nfig = go.Figure(\n    data=[\n        go.Pie(\n            labels=categories,\n            values=values,\n            hole=0.58,\n            marker={\n                \"colors\": colors,\n                \"line\": {\"color\": PAGE_BG, \"width\": 3},  # theme-adaptive separator lines\n            },\n            textinfo=\"label+percent\",\n            textfont={\"size\": 18, \"color\": INK, \"family\": \"Inter, Arial, sans-serif\"},\n            textposition=\"outside\",\n            pull=pull,\n            sort=False,\n            direction=\"clockwise\",\n            rotation=90,\n            insidetextorientation=\"horizontal\",\n            automargin=True,\n            hovertemplate=\"<b>%{label}</b><br>%{percent:.0%}<br>$%{value}M<extra></extra>\",\n        )\n    ]\n)\n\n# Three-level center annotation: header / bold total / year\nfig.add_annotation(\n    text=\"Total Budget\",\n    x=0.5,\n    y=0.62,\n    font={\"size\": 22, \"color\": INK_SOFT, \"family\": \"Inter, Arial, sans-serif\"},\n    showarrow=False,\n)\nfig.add_annotation(\n    text=f\"<b>${total}M</b>\",\n    x=0.5,\n    y=0.5,\n    font={\"size\": 56, \"color\": INK, \"family\": \"Inter, Arial, sans-serif\"},\n    showarrow=False,\n)\nfig.add_annotation(\n    text=\"FY2026\",\n    x=0.5,\n    y=0.38,\n    font={\"size\": 18, \"color\": INK_MUTED, \"family\": \"Inter, Arial, sans-serif\"},\n    showarrow=False,\n)\n\ntitle = \"donut-basic · python · plotly · anyplot.ai\"\nfig.update_layout(\n    autosize=False,\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK, \"family\": \"Inter, Arial, sans-serif\"},\n    title={\"text\": title, \"font\": {\"size\": 16, \"color\": INK}, \"x\": 0.5, \"xanchor\": \"center\"},\n    showlegend=False,\n    margin={\"l\": 80, \"r\": 80, \"t\": 80, \"b\": 80},\n)\n\n# Save — square 2400×2400 px (symmetric donut chart)\nfig.write_image(f\"plot-{THEME}.png\", width=600, height=600, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}