- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
In Matplotlib, show the percentage or proportional data where each slice of pie represents a category
In this article, we can create a pie chart to show our daily activities, i.e., sleeping, eating, working, and playing. Using plt.pie() method, we can create a pie chart with the given different data sets for different activities.
Create a list of days, i.e., [1, 2, 3, 4, 5]. Similarly, make lists for sleeping, eating, playing, and working. There is an activities list that keeps “sleeping”, “eating”, “working” and “playing”.
Make a list of colors.
Use plt.pie() method to draw the pie chart, where slices, activities, colors as cols, etc. are passed.
Set a title for the axes, i.e., “Pie Chart”.
To show the figure use plt.show() method.
import matplotlib.pyplot as plt days = [1, 2, 3, 4, 5] sleeping = [7, 8, 6, 11, 7] eating = [2, 3, 4, 3, 2] working = [7, 8, 7, 2, 2] playing = [8, 5, 7, 8, 13] slices = [7, 2, 3, 13] activities = ['sleeping', 'eating', 'working', 'playing'] cols = ['c', 'm', 'r', 'b'] plt.pie(slices, labels=activities, colors=cols, startangle=90, shadow=True, explode=(0, 0.1, 0, 0), autopct='%1.1f%%') plt.title('Pie Plot') plt.show()
When we execute the code, it will produce the following output −
- How to find the percentage of each category in an R data frame column?
- How to find the percentage of each category in a data.table object column in R?
- How to find the count of each category in an R data frame column?
- How to find the percentage of zeros in each column of a data frame in R?
- How to set a title above each marker which represents a same label in Matplotlib?
- Conditional removal of labels in Matplotlib pie chart
- How to find the percentage of missing values in each column of an R data frame?
- How to plot pie-chart with a single pie highlighted with Python Matplotlib?
- How to find the count of each category in a data.table object column in R?
- How to extract the closest value to a certain value in each category in an R data frame?
- How to plot a nested pie chart in Matplotlib?
- How to show the title for the diagram of Seaborn pairplot() or PridGrid()? (Matplotlib)
- How to find the percentage of zeros in each column of a matrix in R?
- Determine whether the given object represents a scalar data-type in Python
- Which color represents prosperity- Green or Purple?