0
0
Matplotlibdata~5 mins

Why pie charts show proportions in Matplotlib

Choose your learning style9 modes available
Introduction

Pie charts help us see how parts make up a whole. They show proportions by dividing a circle into slices.

You want to show how different categories share a total, like favorite fruits in a group.
You need to compare parts of a budget to the total spending.
You want to display survey results as percentages of all answers.
You want to quickly show which category is biggest or smallest in a dataset.
Syntax
Matplotlib
matplotlib.pyplot.pie(sizes, labels=None, autopct=None, startangle=0)

sizes is a list of numbers representing each slice size.

labels names each slice.

Examples
Simple pie chart with two slices showing 30 and 70 parts.
Matplotlib
sizes = [30, 70]
plt.pie(sizes)
plt.show()
Pie chart with labels for each slice.
Matplotlib
sizes = [10, 20, 30]
labels = ['A', 'B', 'C']
plt.pie(sizes, labels=labels)
plt.show()
Pie chart showing percentage values on each slice.
Matplotlib
sizes = [15, 35, 50]
labels = ['X', 'Y', 'Z']
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.show()
Sample Program

This program creates a pie chart showing how three fruits share a total. The percentages show each fruit's part of the whole.

Matplotlib
import matplotlib.pyplot as plt

sizes = [25, 35, 40]
labels = ['Apples', 'Bananas', 'Cherries']

plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)
plt.title('Fruit Proportions')
plt.show()
OutputSuccess
Important Notes

Pie charts work best with a small number of categories.

Percentages help understand the size of each slice easily.

Start angle rotates the chart for better view.

Summary

Pie charts divide a circle to show parts of a whole.

They use slice sizes to represent proportions.

Labels and percentages make the chart easier to read.