Python matplotlib.pyplot 饼图 : How to remove the label on the left side?

标签 python pandas matplotlib charts pie-chart

我使用 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()

结果:

enter image description here

但是,我无法删除左侧的标签(图中标记为红色)。我已经试过了

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/

相关文章:

python - 在python中并排绘制两个图像

python - Matplotlib - 在 x 轴上隐藏特定刻度

python - SymPy diff() 函数的问题

python - 如何使用 youtube-dl 获取视频信息,无需下载

python - 迭代两个 pandas 数据帧之间的日期范围以获取类别计数

python - 如何评估一组行是否包含特定值?

python - sympy:求解二次方程的结果顺序

Python 上下文管理器未清理

具有分组依据和条件的 Python Pandas 新数据框列

python - Matplotlib 等值线图绘制两个不同的数据