Q:

Python | Create pie-chat using matplotlib.pyplot

belongs to collection: Python miscellaneous programs

0

Create pie-charts in python (using matplotlib.pyplot).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

import matplotlib.pyplot as plt

days = [1, 2, 3, 4, 5]
slices = [7,2,2,13]
cols = ['r','y','g','b']

my_labels = ["Sleeping ", "Eating", "Working", "Playing"]

plt.pie(slices, 
        labels=my_labels, 
        colors = cols, 
startangle=45, 
        explode =(0,0.2,0,0), 
        shadow = True,
autopct = '%1.1f%%')
plt.axis('equal')
plt.legend(loc=3)
plt.show()

Output

pie chart program output in Python

Explanation:

The pie function plots the pie chart. Mylabels attribute is given to the label of the pie function. Explode attribute is used to explode the part of the pie. There is also a shadow attribute in the pie function for giving a shadow effect. In legend function a loc variable is passed to specify the location of the legend.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python miscellaneous programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Create stack plot using matplotlib.pyplot... >>
<< Python | Create a scatter plot using matplotlib.py...