Python ProgrammingPython Programming

Example of plot a pie chart in Python Matplotlib

Plot a pie chart:

plt.pie() draws the pie plot. plt.axis(equal) indicates that the chart should be shown in a circle.

import matplotlib.pyplot as plt


labels = ['India', 'Canada', 'Japan', 'Australia', 'Russia']
sizes = [31, 19, 15, 14, 21]  # Add upto 100%

# Plot the pie chart
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)

# Equal aspect ratio ensures that pie is drawn as a circle.
plt.axis('equal')

# Display the graph onto the screen
plt.show()

The following is the output that will be obtained:


Example of plot a pie chart in Matplotlib