Python matplotlib.pyplot饼图:如何删除左侧的标签? [英] Python matplotlib.pyplot pie charts: How to remove the label on the left side?

查看:415
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆