**
第三天课后作业
**
```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()