------------------------------更新--------------------------------------
原网页https://news.qq.com/zt2020/page/feiyan.htm或已改变,以下代码仅供参参考。
另,可参考另一篇类似博客:https://blog.csdn.net/weixin_43636302/article/details/104289556
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
chinaDayAddList=data["chinaDayAddList"]
dailyNewAddHistory=data["dailyNewAddHistory"]
print(chinaDayAddList)
da=[]
for i in range(len(chinaDayAddList)):
da.append([chinaDayAddList[i]["date"],chinaDayAddList[i]["confirm"] , chinaDayAddList[i]["suspect"], chinaDayAddList[i]["dead"],chinaDayAddList[i]["heal"],chinaDayAddList[i]["deadRate"],chinaDayAddList[i]["healRate"],dailyNewAddHistory[i]["hubei"],dailyNewAddHistory[i]["notHubei"]])
print(da)
df = pd.DataFrame({})
df["date"] = [x[0] for x in da]
df["confirm"] = [x[1] for x in da]
df["suspect"] = [x[2] for x in da]
df["dead"] = [x[3] for x in da]
df["heal"] = [x[4] for x in da]
df["deadRate"] = [x[5] for x in da]
df["healRate"] = [x[6] for x in da]
df["hubei"] = [x[7] for x in da]
df["notHubei"] = [x[8] for x in da]
print(df)
fig = plt.figure(figsize=(10, 5))
count = df.count()['date']
index = np.arange(count)
df['index'] = index
print(df)
#设置横坐标间隔
limit=1
# 设置横坐标的刻度与显示标签
plt.xticks(index[::limit], df['date'][::limit],rotation=90)
plt.title("每日新增疑似和湖北省内外确诊对比")
ax1 = plt.gca()
#设置坐标标题
ax1.set(xlabel='date', ylabel='人数')
#解决画图中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
line1, = ax1.plot(index, df['confirm'], color='black',linestyle= '-',linewidth=2,alpha=0.9,label='confirm')
line2, = ax1.plot(index, df['suspect'], 'grey', label='suspect')
line3, = ax1.plot(index, df['hubei'], color='black',linestyle= '--',linewidth=2,alpha=0.9, label='hubei_confirm')
line4, = ax1.plot(index, df['notHubei'],color='black',linestyle= ':',linewidth=2,alpha=0.9, label='notHubei_confirm')
#设置图例
plt.legend(handles=[line1, line2,line3,line4])
plt.show()
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
chinaDayAddList=data["chinaDayAddList"]
print(chinaDayAddList)
print(len(chinaDayAddList))
da=[]
for i in range(len(chinaDayAddList)):
da.append([chinaDayAddList[i]["date"],chinaDayAddList[i]["confirm"] , chinaDayAddList[i]["suspect"], chinaDayAddList[i]["dead"],chinaDayAddList[i]["heal"],chinaDayAddList[i]["deadRate"],chinaDayAddList[i]["healRate"]])
print(da)
df = pd.DataFrame({})
df["date"] = [x[0] for x in da]
df["confirm"] = [x[1] for x in da]
df["suspect"] = [x[2] for x in da]
df["dead"] = [x[3] for x in da]
df["heal"] = [x[4] for x in da]
df["deadRate"] = [x[5] for x in da]
df["healRate"] = [x[6] for x in da]
print(df)
fig = plt.figure(figsize=(10, 5))
count = df.count()['date']
index = np.arange(count)
df['index'] = index
print(df)
#设置横坐标间隔
limit=1
# 设置横坐标的刻度与显示标签
plt.xticks(index[::limit], df['date'][::limit],rotation=90)
plt.title("每日新增死亡和治愈")
ax1 = plt.gca()
ax2 = ax1.twinx()
#设置坐标标题
ax1.set(xlabel='date', ylabel='人数')
ax2.set(xlabel='date', ylabel='百分点')
#解决画图中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
line1, = ax1.plot(index, df['dead'], color='black',linestyle= '-',linewidth=2,alpha=0.9, label='dead')
line2, = ax1.plot(index, df['heal'], color='g',linestyle= '-',linewidth=2,alpha=0.9, label='heal')
line3, = ax2.plot(index, df['deadRate'], 'black', linestyle= '--',linewidth=2,alpha=0.9,label='deadRate')
line4, = ax2.plot(index, df['healRate'],'g',linestyle= '--',linewidth=2,alpha=0.9, label='healRate')
#设置图例
plt.legend(handles=[line1, line2,line3,line4])
plt.show()
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
chinaDayList=data["chinaDayList"]
# dailyDeadRateHistory=data["dailyDeadRateHistory"]
da=[]
for i in range(len(chinaDayList)):
da.append([chinaDayList[i]["date"],chinaDayList[i]["confirm"] , chinaDayList[i]["suspect"], chinaDayList[i]["dead"],chinaDayList[i]["heal"],chinaDayList[i]["deadRate"],chinaDayList[i]["healRate"],chinaDayList[i]["nowConfirm"],chinaDayList[i]["nowSevere"]])
print(da)
df = pd.DataFrame({})
df["date"] = [x[0] for x in da]
df["confirm"] = [x[1] for x in da]
df["suspect"] = [x[2] for x in da]
df["dead"] = [x[3] for x in da]
df["heal"] = [x[4] for x in da]
df["deadRate"] = [x[5] for x in da]
df["healRate"] = [x[6] for x in da]
df["nowConfirm"]=[x[7] for x in da]
df["nowSevere"]=[x[8] for x in da]
print(df)
fig = plt.figure(figsize=(10, 5))
count = df.count()['date']
index = np.arange(count)
df['index'] = index
print(df)
#设置横坐标间隔
limit=1
# 设置横坐标的刻度与显示标签
plt.xticks(index[::limit], df['date'][::limit],rotation=90)
plt.title("累计确诊和疑似")
ax1 = plt.gca()
#设置坐标标题
ax1.set(xlabel='date', ylabel='人数')
#解决画图中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
line1, = ax1.plot(index, df['confirm'], color='black',linestyle='-',linewidth=2,alpha=0.9, label='confirm')
line2, = ax1.plot(index, df['suspect'], 'grey',linestyle='-',linewidth=2,alpha=0.9, label='suspect')
line3, = ax1.plot(index, df['nowConfirm'], color='black',linestyle='--',linewidth=2,alpha=0.9, label='nowConfirm')
line4, = ax1.plot(index, df['nowSevere'], 'r',linestyle='-',linewidth=2,alpha=0.9, label='nowSevere')
#设置图例
plt.legend(handles=[line1, line2,line3,line4])
plt.show()
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
# chinaDayList=data["chinaDayList"]
dailyDeadRateHistory=data["dailyDeadRateHistory"]
dailyHealRateHistory=data["dailyHealRateHistory"]
da=[]
print(len(dailyDeadRateHistory))
for i in range(len(dailyHealRateHistory)):
da.append([dailyDeadRateHistory[i]["date"],
dailyHealRateHistory[i]["hubeiRate"],
dailyHealRateHistory[i]["notHubeiRate"],
dailyHealRateHistory[i]["countryRate"],
dailyDeadRateHistory[i]["hubeiRate"],
dailyDeadRateHistory[i]["notHubeiRate"],
dailyDeadRateHistory[i]["countryRate"]])
print(da)
df = pd.DataFrame({})
df["date"] = [x[0] for x in da]
df["hubeiRate_heal"] = [x[1] for x in da]
df["notHubeiRate_heal"] = [x[2] for x in da]
df["countryRate_heal"] = [x[3] for x in da]
df["hubeiRate_dead"] = [x[4] for x in da]
df["notHubeiRate_dead"] = [x[5] for x in da]
df["countryRate_dead"] = [x[6] for x in da]
print(df)
fig = plt.figure(figsize=(10, 5))
count = df.count()['date']
index = np.arange(count)
df['index'] = index
print(df)
#设置横坐标间隔
limit=1
# 设置横坐标的刻度与显示标签
plt.xticks(index[::limit], df['date'][::limit],rotation=90)
plt.title("湖北内外确诊累计")
ax1 = plt.gca()
ax2 = ax1.twinx()
#设置坐标标题
ax1.set(xlabel='date', ylabel='百分点')
# ax2.set(xlabel='date', ylabel='百分点')
#解决画图中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
line1, = ax1.plot(index, df['countryRate_heal'], 'g', linestyle='-',linewidth=2,alpha=0.9,label='countryRate_heal')
line2, = ax1.plot(index, df['hubeiRate_heal'], 'g', linestyle='--',linewidth=2,alpha=0.9, label='hubeiRate_heal')
line3, = ax1.plot(index, df['notHubeiRate_heal'], 'g', linestyle=':',linewidth=2,alpha=0.9, label='notHubeiRate_heal')
line4, = ax1.plot(index, df['countryRate_dead'], 'k', linestyle='-',linewidth=2,alpha=0.9, label='countryRate_dead')
line5, = ax1.plot(index, df['hubeiRate_dead'], 'k', linestyle='--',linewidth=2,alpha=0.9, label='hubeiRate_dead')
line6, = ax1.plot(index, df['notHubeiRate_dead'], 'k', linestyle=':',linewidth=2,alpha=0.9, label='notHubeiRate_dead')
# line7, = ax1.plot(index, df['countryConfirm'], 'orange', linestyle='-',linewidth=2,alpha=0.9, label='"countryConfirm')
# line8, = ax1.plot(index, df['hubeiConfirm'], 'orange', linestyle='--',linewidth=2,alpha=0.9, label='hubeiConfirm')
# line9, = ax1.plot(index, df['notHubeiRate'], 'orange', linestyle=':',linewidth=2,alpha=0.9, label='notHubeiRate')
#设置图例
plt.legend(handles=[line1,line2,line3,line4,line5,line6])
plt.show()
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
dailyDeadRateHistory=data["dailyDeadRateHistory"]
da=[]
for i in range(len(dailyDeadRateHistory)):
da.append([dailyDeadRateHistory[i]["date"],dailyDeadRateHistory[i]["hubeiDead"] , dailyDeadRateHistory[i]["hubeiConfirm"], dailyDeadRateHistory[i]["countryDead"],dailyDeadRateHistory[i]["countryConfirm"],dailyDeadRateHistory[i]["hubeiRate"],dailyDeadRateHistory[i]["notHubeiRate"],dailyDeadRateHistory[i]["countryRate"]])
print(da)
df = pd.DataFrame({})
df["date"] = [x[0] for x in da]
df["hubeiDead"] = [x[1] for x in da]
df["hubeiConfirm"] = [x[2] for x in da]
df["countryDead"] = [x[3] for x in da]
df["countryConfirm"] = [x[4] for x in da]
df["hubeiRate"] = [x[5] for x in da]
df["notHubeiRate"] = [x[6] for x in da]
df["countryRate"] = [x[7] for x in da]
df["NotHubeiDead"] = df["countryDead"] - df["hubeiDead"]
df["NotHubeiConfirm"] = df["countryConfirm"] - df["hubeiConfirm"]
print(df)
fig = plt.figure(figsize=(10, 5))
count = df.count()['date']
index = np.arange(count)
df['index'] = index
print(df)
#设置横坐标间隔
limit=1
# 设置横坐标的刻度与显示标签
plt.xticks(index[::limit], df['date'][::limit],rotation=90)
plt.title("湖北内外确诊累计")
ax1 = plt.gca()
#设置坐标标题
ax1.set(xlabel='date', ylabel='人数')
#解决画图中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
line1, = ax1.plot(index, df['countryConfirm'], 'black',linestyle='-',linewidth=2,alpha=0.9, label='countryConfirm')
line2, = ax1.plot(index, df['hubeiConfirm'], 'black',linestyle='--',linewidth=2,alpha=0.9, label='hubeiConfirm')
line3, = ax1.plot(index, df['NotHubeiConfirm'], 'black',linestyle=':',linewidth=2,alpha=0.9, label='NotHubeiConfirm')
#设置图例
plt.legend(handles=[line1, line2,line3])
plt.show()
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
dailyDeadRateHistory=data["dailyDeadRateHistory"]
da=[]
for i in range(len(dailyDeadRateHistory)):
da.append([dailyDeadRateHistory[i]["date"],dailyDeadRateHistory[i]["hubeiDead"] , dailyDeadRateHistory[i]["hubeiConfirm"], dailyDeadRateHistory[i]["countryDead"],dailyDeadRateHistory[i]["countryConfirm"],dailyDeadRateHistory[i]["hubeiRate"],dailyDeadRateHistory[i]["notHubeiRate"],dailyDeadRateHistory[i]["countryRate"]])
print(da)
df = pd.DataFrame({})
df["date"] = [x[0] for x in da]
df["hubeiDead"] = [x[1] for x in da]
df["hubeiConfirm"] = [x[2] for x in da]
df["countryDead"] = [x[3] for x in da]
df["countryConfirm"] = [x[4] for x in da]
df["hubeiRate"] = [x[5] for x in da]
df["notHubeiRate"] = [x[6] for x in da]
df["countryRate"] = [x[7] for x in da]
df["NotHubeiDead"] = df["countryDead"] - df["hubeiDead"]
df["NotHubeiConfirm"] = df["countryConfirm"] - df["hubeiConfirm"]
print(df)
fig = plt.figure(figsize=(10, 5))
count = df.count()['date']
index = np.arange(count)
df['index'] = index
print(df)
#设置横坐标间隔
limit=1
# 设置横坐标的刻度与显示标签
plt.xticks(index[::limit], df['date'][::limit],rotation=90)
plt.title("湖北内外死亡和治愈累计")
ax1 = plt.gca()
ax2 = ax1.twinx()
#设置坐标标题
ax1.set(xlabel='date', ylabel='人数')
ax2.set(xlabel='date', ylabel='百分点')
#解决画图中文乱码问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
line1, = ax1.plot(index, df['countryDead'], 'black', linestyle='-',linewidth=2,alpha=0.9,label='countryDead')
line2, = ax1.plot(index, df['hubeiDead'], 'black', linestyle='--',linewidth=2,alpha=0.9, label='hubeiDead')
line3, = ax1.plot(index, df['NotHubeiDead'], 'black', linestyle=':',linewidth=2,alpha=0.9, label='NotHubeiDead')
line4, = ax2.plot(index, df['countryRate'], 'grey', linestyle='-',linewidth=2,alpha=0.9, label='countryRate')
line5, = ax2.plot(index, df['hubeiRate'], 'grey', linestyle='--',linewidth=2,alpha=0.9, label='hubeiRate')
line6, = ax2.plot(index, df['notHubeiRate'], 'grey', linestyle=':',linewidth=2,alpha=0.9, label='notHubeiRate')
# line7, = ax1.plot(index, df['countryConfirm'], 'orange', linestyle='-',linewidth=2,alpha=0.9, label='"countryConfirm')
# line8, = ax1.plot(index, df['hubeiConfirm'], 'orange', linestyle='--',linewidth=2,alpha=0.9, label='hubeiConfirm')
# line9, = ax1.plot(index, df['notHubeiRate'], 'orange', linestyle=':',linewidth=2,alpha=0.9, label='notHubeiRate')
#设置图例
plt.legend(handles=[line1, line2,line3,line4,line5,line6])
plt.show()