
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to change autopct text color to be white in a pie chart in Matplotlib?
To change the autopct text color to be white in a pie chart in Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Make a list of hours, activities, and colors to plot pie chart.
- Make a list of '.Text' instances for the numeric labels, while making the pie chart.
- Iterate autotexts and set the color of autotext as white.
- 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 plt.figure() hours = [8, 1, 11, 4] activities = ['sleeping', 'exercise', 'studying', 'working'] colors = ["grey", "green", "orange", "blue"] _, _, autotexts = plt.pie(hours, labels=activities, colors=colors, autopct="%.2f") for ins in autotexts: ins.set_color('white') plt.show()
Output
- Related Articles
- How to avoid overlapping of labels & autopct in a Matplotlib pie chart?
- How to plot a nested pie chart in Matplotlib?
- How to add a legend to a Matplotlib pie chart?
- How to plot pie-chart with a single pie highlighted with Python Matplotlib?
- How to have actual values in Matplotlib Pie Chart displayed?
- How to change the text color of font in the legend using Matplotlib?
- Conditional removal of labels in Matplotlib pie chart
- How can I generate more colors on a pie chart in Matplotlib?
- How to change Bar Chart values to percentages in Matplotlib?
- How to change axes background color in Matplotlib?
- How to change text cursor color in Tkinter?
- How to use pie chart graph in android?
- How to create pie chart in base R?
- Explain: How to draw Pie chart?
- How to create a Pie chart using JavaFX?

Advertisements