Matplotlib – Pie Chart
To draw a pie chart using matplotlib python library, use matplotlib.pyplot.pie() function.
In this tutorial, we shall go through some Python example programs which demonstrate the usage of pyplot.pie() function to draw a pie chart in Python.
Example 1: Matplotlib Pie Chart
In the following example, we have taken four sectors. The labels and sizes for these sectors are defined by labels and sizes respectively in the program. The size is used to calculate the angle of the sector.
import matplotlib.pyplot as plt # Data to plot labels = 'Ruby', 'C', 'Python', 'Java' sizes = [215, 130, 245, 210] colors = ['#888888', '#db8b46', '#29b5ce', '#e03364'] explode = (0.01, 0.01, 0.1, 0.01) # explode 1st slice # Plot plt.pie(sizes, explode=explode, labels=labels, colors=colors) plt.axis('equal') plt.show()
In this tutorial of Python Examples, we learned how to draw a pie chart using Matplotlib Python package.