我使用 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()
结果:
但是,我无法删除左侧的标签(图中标记为红色)。我已经试过了
plt.axes().set_xlabel('')
和
plt.axes().set_ylabel('')
但这没有用。
最佳答案
您可以通过调用 pylab.ylabel
来设置 ylabel
:
pylab.ylabel('')
或
pylab.axes().set_ylabel('')
在您的示例中,plt.axes().set_ylabel('')
将不起作用,因为您的代码中没有 import matplotlib.pyplot as plt
,所以plt
不存在。
或者,groups.plot
命令返回 Axes
实例,因此您可以使用它来设置 ylabel
:
ax=groups.plot(kind='pie', shadow=True)
ax.set_ylabel('')
关于Python matplotlib.pyplot 饼图 : How to remove the label on the left side?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34094596/