qiyuan - python画疫情数据分析图,附上爬虫接口

import matplotlib.pyplot as lot
import time
import requests
import json
from datetime import datetime
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=wuwei_ww_cn_day_counts&callback=&_=%d' % int(time.time() * 1000)
print(url)
r = requests.get(url, timeout=20)
print(r.text)
data = json.loads(r.json()['data'])
data.sort(key = lambda x:x['date'])


date_list = []  # 日期列表
confirm_list = [] # 确诊人数
heal_list = [] # 治愈人数
for item in data:
    month,day = item['date'].split('/')
    date_list.append(datetime.strptime("2020-%s-%s"%(month,day),"%Y-%m-%d"))
    confirm_list.append(int(item["confirm"]))
    heal_list.append(int(item["heal"]))


print(date_list)
print(confirm_list)

lot.rcParams['font.sans-serif'] = ['SimHei']
lot.plot(date_list, confirm_list)

lot.plot(date_list, heal_list)
lot.xlabel("时间")
lot.ylabel("治愈人数")
lot.show()

你可能感兴趣的:(学生作品,Qiyuan)