{"spec_id":"area-stacked-percent","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\narea-stacked-percent: 100% Stacked Area Chart\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 81/100 | Updated: 2026-05-12\n\"\"\"\n\nimport pygal\nfrom pygal.style import Style\n\n\n# Data - Market share evolution for tech product categories\nyears = [\"2018\", \"2019\", \"2020\", \"2021\", \"2022\", \"2023\", \"2024\"]\nsmartphones = [42, 40, 38, 36, 35, 33, 32]\nlaptops = [28, 27, 26, 25, 24, 23, 22]\ntablets = [18, 19, 20, 21, 21, 22, 22]\nwearables = [8, 10, 12, 14, 16, 18, 20]\naccessories = [4, 4, 4, 4, 4, 4, 4]\n\n# Custom style for large canvas\ncustom_style = Style(\n    background=\"white\",\n    plot_background=\"white\",\n    foreground=\"#333333\",\n    foreground_strong=\"#333333\",\n    foreground_subtle=\"#666666\",\n    colors=(\"#306998\", \"#FFD43B\", \"#3CB371\", \"#FF6B6B\", \"#9B59B6\"),\n    title_font_size=72,\n    label_font_size=48,\n    major_label_font_size=42,\n    legend_font_size=42,\n    value_font_size=36,\n    opacity=0.85,\n    opacity_hover=0.95,\n    transition=\"250ms ease-in\",\n)\n\n# Create stacked area chart with percentage mode\nchart = pygal.StackedLine(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"area-stacked-percent · pygal · pyplots.ai\",\n    x_title=\"Year\",\n    y_title=\"Market Share (%)\",\n    fill=True,\n    stack_from_top=False,\n    show_y_guides=True,\n    show_x_guides=False,\n    y_labels_major_every=2,\n    truncate_legend=-1,\n    legend_at_bottom=False,\n    legend_box_size=30,\n    margin=50,\n    spacing=40,\n    dots_size=8,\n    stroke_style={\"width\": 3},\n)\n\n# Set x-axis labels\nchart.x_labels = years\n\n# Add data series (values already sum to 100% each year)\nchart.add(\"Smartphones\", smartphones)\nchart.add(\"Laptops\", laptops)\nchart.add(\"Tablets\", tablets)\nchart.add(\"Wearables\", wearables)\nchart.add(\"Accessories\", accessories)\n\n# Save as PNG and HTML\nchart.render_to_png(\"plot.png\")\nchart.render_to_file(\"plot.html\")\n"}