Skip to content

Pie Chart

Pie charts are often hard to compare precisely.

Prefer:

  • Bar charts (best)
  • Donut charts only for simple cases

Still, you may see pie charts in reporting, so here’s how to make one safely.

diagram How a pie chart is built mermaid
Each category's share of the total becomes an angle; all the angles together sweep a full circle.
Pie
import matplotlib.pyplot as plt
 
labels = ["A", "B", "C"]
values = [50, 30, 20]
 
plt.figure(figsize=(6, 6))
plt.pie(values, labels=labels, autopct="%1.0f%%", startangle=90)
plt.title("Category share")
plt.tight_layout()
plt.show()
Explode biggest slice
import matplotlib.pyplot as plt
 
explode = [0.1, 0.0, 0.0]
 
plt.figure(figsize=(6, 6))
plt.pie(values, labels=labels, autopct="%1.0f%%", startangle=90, explode=explode)
plt.title("Category share")
plt.tight_layout()
plt.show()

A pie chart divides a whole into slices, where each slice’s angle is proportional to its share of the total — so all the slices together make up 100%. Watch it build slice by slice:

sketch A pie chart splits a whole into slices p5.js
Each slice's angle is proportional to its share of the total; together they add up to 100%.

If your goal is comparison, use a bar chart.

Continue to Subplots and Figure Size to combine several charts into one dashboard.

Exercise 3 – Convert to a bar chart instead

Section titled “Exercise 3 – Convert to a bar chart instead”

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading