馅饼不允许负值

时间:2019-05-06 10:25:18

标签: python-3.x matplotlib pie-chart

我正在尝试使用Matplotlib绘制饼图,尽管没有负值,但我不断收到错误消息:“ pie不允许负值”!

contrib = sales_data.groupby('Region')['Sales2016'].sum().round().reset_index()
contrib["Percentage"] = (contrib.Sales2016/sum(contrib.Sales2016))*100
contrib = contrib.drop(columns = ["Sales2016"])
contrib.plot(kind = "pie", subplots = True).plot(kind = "pie",subplots=True,legend=False,figsize=(12,5),autopct="%.2f%%")
plt.show()

是否可以指出我要去哪里错了?以下是contrib的输出:

Region  Percentage
0   Central 32.994771
1   East    42.701319
2   West    24.303911

1 个答案:

答案 0 :(得分:0)

在饼图中定义自变量y

 contrib.plot(kind = "pie",y="Percentage",labels=['Region'],legend=False,figsize=(12,5),autopct="%.2f%%")

enter image description here