- 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 replace auto-labelled relative values by absolute values in Matplotlib?
To replace auto-labelled relayive values by absolute values in matplotlib, we can use autopct=lambda p: <calculation for result>.
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 display Matplotlib Y-axis range using absolute values rather than offset values?
- How to Average the Absolute Values in Excel?
- Program to update list items by their absolute values in Python
- How to replace values in a Python dictionary?
- How to replace values of select return in MySQL?
- How to replace values in a vector with values in the same vector in R?
- Absolute Values Sum Minimization in JavaScript
- What is the correct way to replace matplotlib tick labels with computed values?
- How to replace NaN values by Zeroes in a column of a Pandas Series?
- How to replace NaN values by Zeroes in a column of a Pandas DataFrame?
- How to replace values of a Python dictionary?
- How to display all label values in Matplotlib?
- Adjust one subplot's height in absolute way (not relative) in Matplotlib
- How to use pandas series.fillna() to replace missing values?
- How to Auto-Insert Rows Based on Cell Values in Excel?

Advertisements