- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to have actual values in Matplotlib Pie Chart displayed?
To have actual or any custom values in Matplotlib pie chart displayed, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Make lists of labels, fractions, explode position and get the sum of fractions to calculate the percentage
- Make a pie chart using labels, fracs and explode with autopct=lambda p: <calculation for percentage>.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True labels = ('Read', 'Eat', 'Sleep', 'Repeat') fracs = [5, 3, 4, 1] total = sum(fracs) explode = (0, 0.05, 0, 0) plt.pie(fracs, explode=explode, labels=labels, autopct=lambda p: '{:.0f}%'.format(p * total / 100), shadow=True, startangle=90) plt.show()
Output
- Related Articles
- How to plot a nested pie chart in Matplotlib?
- How to plot pie-chart with a single pie highlighted with Python Matplotlib?
- How to add a legend to a Matplotlib pie chart?
- Conditional removal of labels in Matplotlib pie chart
- How to avoid overlapping of labels & autopct in a Matplotlib pie chart?
- How can I generate more colors on a pie chart in Matplotlib?
- How to change autopct text color to be white in a pie chart in Matplotlib?
- Explain: How to draw Pie chart?
- How to use pie chart graph in android?
- How to create pie chart in base R?
- How to Create a Pie Chart in Seaborn?
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- How to change Bar Chart values to percentages in Matplotlib?
- How to create pie chart using plotly in R?
- How to create a Pie chart using JavaFX?

Advertisements