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

北战南征 提交于 2020-01-22 13:22:12

问题


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:

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.


回答1:


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('')


来源:https://stackoverflow.com/questions/34094596/python-matplotlib-pyplot-pie-charts-how-to-remove-the-label-on-the-left-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!