Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to remove the label on the left side in matplotlib.pyplot pie charts?
To remove the label on the left side in a matplotlib pie chart, we can use plt.ylabel("") with a blank string. This removes the default y-axis label that matplotlib automatically adds to pie charts.
Steps to Remove Left Side Label
Create data for the pie chart (values, labels, colors)
Plot a pie chart using
pie()methodUse
plt.ylabel("")to hide the left side label
Example
Here's how to create a pie chart without the left side label ?
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
hours = [8, 1, 11, 4]
activities = ['sleeping', 'exercise', 'studying', 'working']
colors = ["grey", "green", "orange", "blue"]
plt.pie(hours, labels=activities, colors=colors, autopct="%.2f")
plt.ylabel("") # Remove the left side label
plt.show()
Alternative Method Using axis Parameter
You can also remove the y-axis label by setting it to None ?
import matplotlib.pyplot as plt
hours = [8, 1, 11, 4]
activities = ['sleeping', 'exercise', 'studying', 'working']
colors = ["grey", "green", "orange", "blue"]
fig, ax = plt.subplots()
ax.pie(hours, labels=activities, colors=colors, autopct="%.2f")
ax.set_ylabel("") # Remove y-axis label using axes method
plt.show()
Key Points
plt.ylabel("")sets an empty string as the y-axis labelax.set_ylabel("")works when using subplot approachBoth methods effectively hide the default label on the left side
The pie chart functionality remains unchanged, only the label is hidden
Conclusion
Use plt.ylabel("") to remove the left side label in matplotlib pie charts. This simple method eliminates unwanted axis labels while preserving the chart's appearance and functionality.
