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(),它是一个饼图
答案 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}}
这将显示您的饼图,如下所示: