Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plotting Pandas DataFrames in Pie Charts using Matplotlib
To plot Pandas data frames in Pie charts using Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Make a dataframe of two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Plot the dataframe with activities index using pie() method
- To display the figure, use show() method.
Example
import pandas as pd
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
df = pd.DataFrame({'activities': ['sleep', 'exercise', 'work', 'study'],
'hours': [8, 1, 9, 6]})
df.set_index('activities').plot.pie(y='hours', legend=False,
autopct='%1.1f%%')
plt.show()
Output

Advertisements