在matplotlib上删除pyplot.pie()的自动字幕?

时间:2017-09-19 09:24:25

标签: python matplotlib

import matplotlib.pyplot as plt

slices = [45,20,30]
activities = ['sleeping','eating','working']

plt.pie(slices,startangle=90,labels=activities,shadow=True,autopct='%1.1f%%',colors=['b','g','c'])
plt.axis('equal')

plt.savefig('nomeDaFigura.png')  

plt.title('Interesting Graph\nCheck it out')

plt.legend()
plt.show()

我只想要方法plt.legend(),它是一个饼图

1 个答案:

答案 0 :(得分:1)

如果您只想在labels内显示legend,则解决方案是不将其传递给pie(),而是将legend()调用传递给import matplotlib.pyplot as plt slices = [45, 20, 30] activities = ['sleeping', 'eating', 'working'] plt.pie(slices, startangle=90, shadow=True, autopct='%1.1f%%', colors=['b','g','c']) plt.axis('equal') plt.savefig('nomeDaFigura.png') plt.title('Interesting Graph\nCheck it out') plt.legend(labels=activities) plt.show() 如下:

{{1}}

这将显示您的饼图,如下所示:

pie with labels only in legend