{"spec_id":"pie-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\npie-basic: Basic Pie Chart\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-05-28\n\"\"\"\n\nimport os\n\nimport plotly.graph_objects as go\n\n\n# Theme\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# Data - Digital payment processor market share (2024)\nprocessors = [\"Visa\", \"Mastercard\", \"PayPal\", \"Amex\", \"Apple Pay\", \"Others\"]\nmarket_share = [38, 26, 18, 7, 5, 6]\nrankings = [1, 2, 3, 4, 5, 6]\n\n# Colors - Imprint palette positions 1-6\ncolors = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\"]\n\n# Pure pie chart (no donut hole — per spec)\nfig = go.Figure(\n    data=[\n        go.Pie(\n            labels=processors,\n            values=market_share,\n            customdata=rankings,\n            texttemplate=\"%{label}<br>%{percent:.0%}\",\n            textposition=\"inside\",\n            insidetextorientation=\"horizontal\",\n            textfont={\"size\": 13, \"color\": \"#FFFFFF\"},\n            hovertemplate=(\"<b>%{label}</b><br>%{value}% market share<br>Rank #%{customdata} globally<extra></extra>\"),\n            marker={\"colors\": colors, \"line\": {\"color\": PAGE_BG, \"width\": 3}},\n            pull=[0.08, 0, 0, 0, 0, 0],\n            sort=False,\n            direction=\"clockwise\",\n            rotation=90,\n            domain={\"x\": [0.02, 0.70], \"y\": [0.07, 0.93]},\n        )\n    ]\n)\n\n# Market leader callout (above legend)\nfig.add_annotation(\n    text=\"<b>Market Leader</b><br>Visa leads<br>with 38% share\",\n    x=0.86,\n    y=0.88,\n    xref=\"paper\",\n    yref=\"paper\",\n    showarrow=False,\n    font={\"size\": 9, \"color\": colors[0], \"family\": \"Arial, sans-serif\"},\n    xanchor=\"center\",\n    yanchor=\"middle\",\n    bgcolor=ELEVATED_BG,\n    bordercolor=colors[0],\n    borderwidth=1,\n    borderpad=6,\n    align=\"center\",\n)\n\n# Source note\nfig.add_annotation(\n    text=\"Source: Industry estimates, 2024\",\n    x=0.36,\n    y=0.02,\n    xref=\"paper\",\n    yref=\"paper\",\n    showarrow=False,\n    font={\"size\": 9, \"color\": INK_MUTED, \"family\": \"Arial, sans-serif\"},\n    xanchor=\"center\",\n    yanchor=\"bottom\",\n)\n\n# Layout\nfig.update_layout(\n    autosize=False,\n    title={\n        \"text\": (\n            \"pie-basic · python · plotly · anyplot.ai\"\n            f\"<br><span style='font-size:11px;color:{INK_SOFT}'>\"\n            \"Global digital payment market share, 2024</span>\"\n        ),\n        \"font\": {\"size\": 16, \"color\": INK, \"family\": \"Arial, sans-serif\"},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n        \"y\": 0.98,\n    },\n    legend={\n        \"font\": {\"size\": 12, \"color\": INK_SOFT},\n        \"orientation\": \"v\",\n        \"yanchor\": \"middle\",\n        \"y\": 0.5,\n        \"xanchor\": \"left\",\n        \"x\": 0.74,\n        \"bgcolor\": ELEVATED_BG,\n        \"bordercolor\": INK_SOFT,\n        \"borderwidth\": 1,\n    },\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK},\n    margin={\"t\": 60, \"b\": 35, \"l\": 20, \"r\": 20},\n    uniformtext={\"minsize\": 10, \"mode\": \"hide\"},\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=600, height=600, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}