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

本博客展示了如何使用Python的requests库获取疫情数据,并利用matplotlib库进行数据可视化,绘制了确诊、疑似、死亡及治愈病例的时间序列图。此外,还通过matplotlib库绘制了一个数学函数的图形,展现了其强大的绘图能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值