alex -新型冠状病毒确诊病例统计图

import time, json, requests
from datetime import datetime
import matplotlib.pyplot as plt
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=wuwei_ww_cn_day_counts&callback=&_=%d' % int(time.time() * 1000)
print(url)

data =  json.loads(requests.get(url).json()['data'])
data.sort(key=lambda x:x['date'])
print(data)

date_list = [] # 日期
confirm_list = []  # 确诊人数
suspect_list = [] # 疑似病例
dead_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']))
    suspect_list.append(int(item['suspect']))
    dead_list.append(int(item['dead']))
    heal_list.append(int(item['heal']))

# x
print(date_list)
# y
print(confirm_list)

# 画图显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']

plt.plot(date_list,confirm_list)
plt.plot(date_list,suspect_list)



plt.xlabel("时间")
plt.ylabel("确诊人数")
plt.title("新型冠状病毒统计图")
plt.show()



import matplotlib.pyplot as plt
# import numpy as np
# 设置x轴的数据和y轴的数据
x = []
for i in range(-500,500):
    x.append(i)
# 反比例函数  y=-1/x
y = []
for i in x:
    y.append(i**37)

# 画折线图 plot
plt.plot(x, y)
# x轴标题 xlabel
plt.xlabel('x')
plt.ylabel('y')



# 展示 show
plt.show()


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