2015-12-04 81 views
6

我使用pyplot绘制了一个饼图。Python matplotlib.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('') 

,但没有奏效。

+1

贵国是否能再现这个小例子?我没有在matplotlib/Pandas的任何饼图中看到额外的(左)标签... – Bart

+0

@Bart我编辑了我的代码 – Marc

+1

我现在看到Pandas默认是这样做的,请参阅[documentation/examples](http: //pandas.pydata.org/pandas-docs/stable/visualization.html#pie-plot)。但我不知道如何压制这个...... – Bart

回答

4

你可以只设置ylabel通过调用pylab.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('') 
+0

'ax.set_ylabel('')'完美地工作。谢谢! – Marc

+0

也适合我! – Pieter