Python 如何在matplotlib中自动标记数据?

Python 如何在matplotlib中自动标记数据?,python,matplotlib,label,pie-chart,Python,Matplotlib,Label,Pie Chart,我想找到标记数据的快捷方式,因为我使用的是大型数据集 以下是我从大型数据集中绘制的数据: Nationality Afghanistan 4 Albania 40 Algeria 60 Andorra 1 Angola 15 ... Uzbekistan 2 Venezuela 67 Wales 129 Zambia 9 Zimb

我想找到标记数据的快捷方式,因为我使用的是大型数据集

以下是我从大型数据集中绘制的数据:

Nationality
Afghanistan      4
Albania         40
Algeria         60
Andorra          1
Angola          15
              ...
Uzbekistan       2
Venezuela       67
Wales          129
Zambia           9
Zimbabwe        13
Name: count, Length: 164, dtype: int64
到目前为止,这是我的代码:

import pandas as pd 
import matplotlib.pyplot as plt 

the_data = pd.read_csv('fifa_data.csv')

plt.title('Percentage of Players from Each Country')

the_data['count'] = 1
Nations = the_data.groupby(['Nationality']).count()['count']

plt.pie(Nations)
plt.show()

用这种方法创建饼图既简单又快速,但我还没有弄清楚如何在饼图中自动标记每个国家,而不必逐个标记每个数据点。

pandas
绘图功能将为您自动标记数据

# count:
Nations = the_data.groupby('Nationality').size()

# plot data
Nations.plot.pie()

plt.title('Percentage of Players from Each Country')
plt.show()