Python matplotlib.pyplot饼图:如何删除左侧的标签? [英] Python matplotlib.pyplot pie charts: How to remove the label on the left side?
本文介绍了Python matplotlib.pyplot饼图:如何删除左侧的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用pyplot绘制了一个饼图.
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()
结果:
但是,我无法删除左侧的标签(图片中标记为红色).我已经尝试过了
However, I'm unable to remove the label on the left (marked red in the picture). I already tried
plt.axes().set_xlabel('')
和
plt.axes().set_ylabel('')
但是那没用.
推荐答案
您可以通过调用pylab.ylabel
来设置ylabel
:
You could just set the ylabel
by calling pylab.ylabel
:
pylab.ylabel('')
或
pylab.axes().set_ylabel('')
在您的示例中,plt.axes().set_ylabel('')
将不起作用,因为您的代码中没有import matplotlib.pyplot as plt
,因此plt
不存在.
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.
或者,groups.plot
命令返回Axes
实例,因此您可以使用它来设置ylabel
:
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('')
这篇关于Python matplotlib.pyplot饼图:如何删除左侧的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文