Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python matplotlib.pyplot pie charts: How to remove the label on the left side?

I plot a piechart using pyplot.

import pylab
import pandas as pd
test = pd.Series(['male', 'male', 'male', 'male', 'female'], name="Sex")
test = test.astype("category")
groups = test.groupby([test]).agg(len)
groups.plot(kind='pie', shadow=True)
pylab.show()

The result:

enter image description here

However, I'm unable to remove the label on the left (marked red in the picture). I already tried

plt.axes().set_xlabel('')

and

plt.axes().set_ylabel('')

but that did not work.

like image 610
Marc Avatar asked Dec 04 '15 18:12

Marc


People also ask

How do you avoid overlapping of labels and Autopct in a Matplotlib pie chart?

Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.

How do you get rid of the legend in a pie chart in Python?

Example 1: By using ax. legend_ = None, legend can be removed from figure in matplotlib.


3 Answers

You could just set the ylabel by calling pylab.ylabel:

pylab.ylabel('')

or

pylab.axes().set_ylabel('')

In your example, plt.axes().set_ylabel('') will not work because you dont have import matplotlib.pyplot as plt in your code, so plt doesn't exist.

Alternatively, the groups.plot command returns the Axes instance, so you could use that to set the ylabel:

ax=groups.plot(kind='pie', shadow=True)
ax.set_ylabel('')
like image 101
tmdavison Avatar answered Oct 18 '22 04:10

tmdavison


Or:

groups.plot(kind='pie', shadow=True, ylabel='')

like image 5
marcio Avatar answered Oct 18 '22 05:10

marcio


Add label="" argument when using the plot function

groups.plot(kind='pie', shadow=True,label="")
like image 2
Roshan Avatar answered Oct 18 '22 06:10

Roshan