在 matplotlib 饼图中显示正确的标签

showing proper labels in matplotlib pie chart

我正在尝试使用 matplotlib 构建饼图。这是我的代码:

party = data['Name'].groupby(data['Party']).count()
party

以上代码导致:

Party
The Centre Party                22
The Christian Democrats         16
The Green Party                 25
The Left Party                  21
The Liberal Party               19
Name: Name, dtype: int64

然后,下面的代码

"plt.pie(party, labels=party)" 

创建一个以这些值(例如 22、16、25)作为标签的饼图。

我想要的是将这些派对名称显示为标签。有什么建议吗?提前致谢。

我相信你可以使用-

plt.pie(party, labels=party.index)