Plot Pie Charts in Python with Matplotlib — A Tasty Guide for Beginners

Ever wondered how to make pie charts in Python that don’t look like your math textbook from 6th grade? Well, you’re in for a treat — because we’re serving some sweet plots with Matplotlib today. Whether you’re a data newbie or just here to make things look cute, this guide’s got you covered. Let’s slice through the code and make your data deliciously visual

Why Use Pie Charts?

Because sometimes, you just want to show how the cake is divided . Pie charts make it super easy to visualize proportions — who got the biggest slice, who got none, and everything in between. They're quick, clean, and instantly understandable, especially when dealing with simple categorical data.

What You’ll Learn




New to Python? Don't worry — installing Matplotlib is super easy

Just open your terminal and run: pip install matplotlib. That’s all you need to get started!



Step-by-Step Code Example

Here’s a simple example of how to create a pie chart in Matplotlib:

Python

import matplotlib.pyplot as plt

# Meme names
memes = [
    "Pepe the Frog",
    "Doge",
    "This Is Fine Dog",
    "Distracted Boyfriend",
    "Woman Yelling at a Cat",
    "Grumpy Cat"
]

# Years they've been famous (as of 2025)
years_famous = [17, 12, 12, 8, 6, 13]

colors = ['#9fcbf5', '#67a6e0', '#2b85d9', '#1862a8', '#1b4f80', '#073b6b']

plt.pie(years_famous, labels=memes, autopct='%1.1f%%', startangle=140, colors=colors)
plt.title("Top 6 Memes by Years of Popularity (as of 2025)", fontdict={'fontsize': 16, 'fontname': 'Comic Sans MS'})
plt.show()

        

This pie chart visualizes how long the top 6 legendary internet memes have been famous (as of 2025). Instead of numbers or dry stats, it celebrates meme culture with flair.

Quick Highlights:



Here's the output :



Not gonna lie, my color palette feels pretty pro.





Brace yourself — cool pie chart stuff incoming




🔹Exploding Slices: Making One Piece Pop


explodes = [0, 0.1, 0, 0, 0, 0]
        

Sometimes, you want a slice of the pie to stand out — maybe it’s the most important, or you just want it to scream “look at me!” That’s where explode comes in — it pulls out specific slices to grab attention.




🔹Separate Legends, Clearer Vibes


plt.legend(memes, title="Memes", loc="upper left", bbox_to_anchor=(1, 1))
        

Instead of crowding the pie chart with labels inside the slices (which can get messy), we used plt.legend() to place the labels outside the chart — neat and clear.






🔹Donut Vibes with wedgeprops


plt.pie(data, wedgeprops=dict(width=0.7))
        

Want to turn your regular pie chart into a donut chart? That’s where wedgeprops comes in!






When to Use Pie Charts (And When You Definitely Shouldn’t)

Pie charts are great, but not for every situation. Let’s break it down:




Looking to level up? Explore more premium learning content through the links below :