×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Create pie-chart using matplotlib.pyplot

Here, we are implementing a python program to create a pie-chart using matplotlib.pyplot.
Submitted by Ayush Sharma, on November 25, 2018

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

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.


Related Programs

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.