Create a Simple Pie Chart in Python

thumbnail

In this tutorial, you will learn to create a simple pie chart in python. First, you need to import matplotlib. Then, you implement the source code below.

import matplotlib.pyplot as plt

# Pie chart Data
slices_hours = [20,20,25,30,5]
activites = ['SciFi', 'Comedy', 'Action', 'Romance', 'Drama']
colors = ['Red','Green','Yellow','Blue','Purple']

fig = plt.figure(1, figsize=(6,6))
ax = fig.add_axes([0.2, 0.2, 0.8, 0.8])
plt.title('Favourite Type of Movie')

_, _, autotexts = ax.pie(slices_hours, labels=activites, colors=colors, startangle=90, autopct='%.1f%%', pctdistance=0.5, textprops={'color':"black"})
plt.show()

The output will be:

 

Back To Top