【问题标题】:how to automate labeling of data in matplotlib?如何在 matplotlib 中自动标记数据?
【发布时间】:2020-05-19 18:55:52
【问题描述】:

由于我正在处理大型数据集,因此我想找到标记数据的快捷方式。

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

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()

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

【问题讨论】:

    标签: python matplotlib label pie-chart


    【解决方案1】:

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

    # count:
    Nations = the_data.groupby('Nationality').size()
    
    # plot data
    Nations.plot.pie()
    
    plt.title('Percentage of Players from Each Country')
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 2020-07-25
      • 1970-01-01
      相关资源
      最近更新 更多