第三天课后作业

**

第三天课后作业

**


```python
import matplotlib.pyplot as plt
import numpy as np
import json
import matplotlib.font_manager as font_manager

with open('data/data31557/20200422.json', 'r', encoding='UTF-8') as file:
         json_array = json.loads(file.read())

#显示matplotlib生成的图形
# %matplotlib inline
error_list=['k','g']

weights = []
for star in json_array:
    weight = star['weight']
    for c in weight:
        if c in error_list:
            weight=weight.replace(c,'')#去除选手体重中的‘kg’字符
            #weight=float(star['weight'].repalce('kg',''))
    # print(type(weight))
    weights.append(weight)
print(len(weights))
print(weights)

# num=len(weights)

size_1=0
size_2=0
size_3=0
size_4=0

for i in range(len(weights)):
    if weights[i] <= '45':
        size_1+=1
        continue
    elif weights[i]<='50' and weights[i]>'45':
        size_2+=1
        continue
    elif weights[i]<='55' and weights[i]>'50':
        size_3+=1
        continue
    else:
        size_4+=1
print(size_1)
print(size_2)
print(size_3)
print(size_4)

sizes=[size_1,size_2,size_3,size_4]
labels='小于45kg','45~50kg','50~55kg','大于55kg'
explode = (0,0.1,0,0.2) #饼图中的显示突出出来

plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%',shadow=False,startangle=150)
plt.axis('equal')#设置饼图为正圆形式,而非椭圆
plt.title("饼图示例-《青春有你2》选手体重")
plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值