Pie Charts, Donut Charts, and Alternatives
Pie charts are familiar and popular, but they are also easy to misuse. This topic shows how to create them well, when to avoid them, and which charts can do a better job for showing proportions.
a. Creating Pie Charts
A pie chart divides a circle into slices, where each slice shows a share of the whole. Use plt.pie() and pass the values and labels.
labels = ["Mobile", "Laptop", "Tablet"]
share = [60, 30, 10]
fig, ax = plt.subplots()
ax.pie(share, labels=labels, autopct="%1.1f%%", startangle=90)
ax.set_title("Sales by Device")
plt.show()The autopct setting writes the percentage on each slice. The startangle setting rotates the chart so that the first slice starts at the top.
Pie charts work best with two to five slices. The values must add up to a meaningful whole, such as 100 percent of sales.
b. Building Donut Charts
A donut chart is a pie chart with a hole in the middle. It looks cleaner and gives space to place a total or a key number in the center.
ax.pie(share, labels=labels, autopct="%1.1f%%",
wedgeprops={"width": 0.4})
ax.text(0, 0, "100%", ha="center", va="center", fontsize=16)The width setting inside wedgeprops controls how thick the ring is. A smaller value gives a thinner ring.
Donut charts share the same strengths and limits as pie charts. They are good for a quick view of shares but are not ideal for precise comparison.
c. When Not to Use Pie Charts
The human eye is good at comparing lengths but poor at comparing angles and areas. This makes it hard to tell the difference between slices of similar size in a pie chart.
Avoid pie charts when you have many categories, when slices are very close in size, or when you want to compare values across several pies. In these cases, the chart becomes cluttered and confusing.
Also avoid 3D pie charts. The tilt distorts the sizes of the slices and can mislead the viewer. Flat charts are always more honest.
d. Better Alternatives for Showing Proportions
A sorted bar chart is often the best alternative. It makes it easy to compare shares and to read exact values, even when there are many categories.
A stacked bar chart that adds up to 100 percent can show how proportions change across groups. A treemap is another option when you have many categories and want to show relative sizes with rectangles.
Choose the one that best fits the question. If the goal is to show that one part is much larger than the rest, a pie chart may still work. Otherwise, a bar chart is a safer choice.
Data Visualization Tutorial
Wesline Rinisha








