python - 如何在 matplotlib 中自动标记数据?
问题描述
由于我正在处理大型数据集,因此我想找到标记数据的快捷方式。
这是我从大型数据集中绘制的数据:
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()
推荐阅读
- javascript - 按下按钮时传递值
- php - PHP ODBC 数据类型不匹配 (MS Access)
- javascript - 用于 html 内文本的 javascript 荧光笔
- java - AspectJ、SpringAOP、Aspect 运行两次
- r - 根据现有变量的值创建一个新的指标变量
- android - 手机深度睡眠时与服务器通信
- c++ - 为什么我们在访问者模式中需要 accept() 以及为什么我们不能直接调用 visitor.visit()?
- c - 为什么 '?' 和 '\?' 在 C 中给出相同的输出?
- python - 我有一个对应于 2018 年第 1 周的 ISO 8601 周数(例如:201801)。pyth 中的最佳方法是什么
- vba - 如何在 Outlook 中添加消息框以发送按钮?