{"spec_id":"pie-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\npie-basic: Basic Pie Chart\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 88/100 | Updated: 2026-05-28\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Circle\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# anyplot categorical palette — positions 1→5\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\"]\n\n# Data — global cloud infrastructure market share (2024)\ncompanies = [\"AWS\", \"Azure\", \"Google Cloud\", \"Alibaba Cloud\", \"Others\"]\nmarket_share = [31, 25, 11, 4, 29]\n\n# Explode the largest slice (AWS) for emphasis\nexplode = [0.08, 0, 0, 0, 0]\n\n# Plot — square canvas, appropriate for pie charts\nfig, ax = plt.subplots(figsize=(6, 6), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nwedges, texts, autotexts = ax.pie(\n    market_share,\n    labels=companies,\n    autopct=\"%1.1f%%\",\n    explode=explode,\n    colors=IMPRINT_PALETTE,\n    startangle=90,\n    textprops={\"fontsize\": 10, \"color\": INK},\n    wedgeprops={\"linewidth\": 2, \"edgecolor\": PAGE_BG},\n    pctdistance=0.72,\n    labeldistance=1.15,\n)\n\n# Percentage labels: bold white for contrast against colored slices\nfor autotext in autotexts:\n    autotext.set_fontsize(9)\n    autotext.set_fontweight(\"bold\")\n    autotext.set_color(\"white\")\n\n# Center context medallion — matplotlib.patches overlay: adds data context\n# and showcases the library's direct primitive drawing capability\ncenter_fill = Circle((0, 0), 0.30, color=PAGE_BG, zorder=5)\ncenter_ring = Circle((0, 0), 0.30, fill=False, edgecolor=INK_MUTED, linewidth=0.8, zorder=6)\nax.add_patch(center_fill)\nax.add_patch(center_ring)\nax.text(0, 0.07, \"2024\", ha=\"center\", va=\"center\", fontsize=9, fontweight=\"bold\", color=INK, zorder=7)\nax.text(0, -0.08, \"Global Cloud\", ha=\"center\", va=\"center\", fontsize=7, color=INK_MUTED, zorder=7)\n\n# Title — reduced pad to eliminate unused vertical whitespace\nax.set_title(\"pie-basic · python · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=10)\n\n# Legend — category identification\nleg = ax.legend(\n    wedges,\n    companies,\n    title=\"Cloud Providers\",\n    loc=\"lower center\",\n    bbox_to_anchor=(0.5, -0.08),\n    fontsize=8,\n    title_fontsize=9,\n    ncol=3,\n)\nleg.get_frame().set_facecolor(ELEVATED_BG)\nleg.get_frame().set_edgecolor(INK_SOFT)\nplt.setp(leg.get_texts(), color=INK_SOFT)\nleg.get_title().set_color(INK)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}