栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

第三天课后作业

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第三天课后作业

**

第三天课后作业

**

```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()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/701297.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号