Pie Charts
A pie chart shows how a whole is split into parts. Each category gets a slice whose angle is proportional to its share: a category with relative frequency f / n gets 360° × f / n of the circle.
Pie charts work well when:
- the data is categorical,
- the parts add up to a meaningful whole (100% of something),
- there are only a few categories (about 2–6),
- you want to show part-to-whole relationships ("almost half of our users are on mobile").
They work badly when slices are similar in size, when there are many categories, or when you need to compare several pies. Humans judge angles and areas much less precisely than lengths, which is why a bar chart is often the better choice.
From frequencies to angles
A small streaming service asked 200 subscribers which device they mostly watch on:
devices = {"TV": 92, "phone": 54, "laptop": 38, "tablet": 16}
total = sum(devices.values())
print(f"{'device':8s} {'f':>4s} {'share':>7s} {'angle':>7s}")
for name, f in devices.items():
share = f / total
print(f"{name:8s} {f:4d} {share:7.1%} {360 * share:6.1f}°")
print("angles add up to", round(sum(360 * f / total for f in devices.values()), 1))device f share angle
TV 92 46.0% 165.6°
phone 54 27.0% 97.2°
laptop 38 19.0% 68.4°
tablet 16 8.0% 28.8°
angles add up to 360.0
Drawing a pie chart
import matplotlib.pyplot as plt
devices = ["TV", "phone", "laptop", "tablet"]
viewers = [92, 54, 38, 16]
colors = ["#2a78d6", "#eb6834", "#1baf7a", "#eda100"]
fig, ax = plt.subplots(figsize=(4.5, 4.5))
ax.pie(viewers, labels=devices, colors=colors, autopct="%1.0f%%",
startangle=90, counterclock=False,
wedgeprops={"edgecolor": "white", "linewidth": 2})
ax.set_title("Main viewing device (n = 200)")
plt.tight_layout()
plt.show()
print("Pie chart with", len(devices), "slices")Pie chart with 4 slices
autopctprints each slice's percentage.startangle=90, counterclock=Falsestarts at 12 o'clock and goes clockwise, the order most readers expect.- A white edge between slices keeps neighbouring colours apart.
Too many slices? Group the small ones
With many small categories, combine the smallest into "Other" so the chart stays readable:
import pandas as pd
languages = pd.Series({"English": 412, "Spanish": 133, "French": 61, "German": 38,
"Italian": 21, "Dutch": 12, "Polish": 9, "Greek": 6})
share = languages / languages.sum()
main = languages[share >= 0.05]
grouped = pd.concat([main, pd.Series({"Other": languages[share < 0.05].sum()})])
print((grouped / grouped.sum()).round(3))English 0.595
Spanish 0.192
French 0.088
German 0.055
Other 0.069
dtype: float64
Eight slices became five, and the "Other" slice still keeps the total honest.
Pie or bar? A side-by-side comparison
When the parts are close in size, try to rank the slices of the pie below, then check the bars:
import matplotlib.pyplot as plt
teams = ["A", "B", "C", "D", "E"]
votes = [21, 19, 22, 18, 20]
colors = ["#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4"]
fig, (pie_ax, bar_ax) = plt.subplots(1, 2, figsize=(9, 3.5))
pie_ax.pie(votes, labels=teams, colors=colors, startangle=90, counterclock=False,
wedgeprops={"edgecolor": "white", "linewidth": 2})
pie_ax.set_title("hard to rank")
bar_ax.bar(teams, votes, color="#2a78d6", width=0.6)
bar_ax.set_title("easy to rank")
fig.tight_layout()
plt.show()
print("ranking:", sorted(teams, key=lambda t: votes[teams.index(t)], reverse=True))ranking: ['C', 'A', 'E', 'B', 'D']
The slices look almost identical, but the bars immediately reveal that team C leads and team D trails.
Tip: Avoid 3D pies, exploded slices and pies of data that doesn't add up to a whole (e.g. "% of respondents who mentioned each feature" when people could pick several). Each of these distorts the reader's sense of proportion.
Test yourself
A category makes up 15% of the data. How large is its slice?
- 15°
- 36°
- 54°
- 90°
Which data is suitable for a pie chart?
- Daily temperatures over a month
- Share of a budget spent on 4 departments
- Heights of 300 students
- Survey where respondents could choose several answers
Why are bar charts often preferred over pie charts?
- Bars use less ink
- People compare lengths more accurately than angles or areas
- Pies can't show percentages
- Bars work only for categorical data