数据可视化 世界疫情地图
程序员文章站
2022-06-01 12:50:11
...
绘制世界疫情地图并显示当天确诊人数
## https://zhuanlan.zhihu.com/p/122971494
## 获取全部数据:https://coronavirus-tracker-api.herokuapp.com/all
##
## 获取确诊数据:https://coronavirus-tracker-api.herokuapp.com/confirmed
##
## 获取死亡数据:https://coronavirus-tracker-api.herokuapp.com/deaths
##
## 获取治愈数据:https://coronavirus-tracker-api.herokuapp.com
import requests
import json
from pyecharts import Map, Geo
fq=open("information.txt","r")
json_text=json.loads(fq.read())#读取文件
date="12/20/20"
'''
location=json_text["confirmed"]["locations"][0]["country"]
data=json_text["confirmed"]["locations"][0]["history"]["3/12/20"]
print(str(data[0])+" "+location)
'''
value=[]
attr=[]
ussum=0
chinasum=0
Canadasum=0
UKsum=0
Australiasum=0
Francesum=0
for i in range(0,len(json_text["confirmed"]["locations"])):
if json_text["confirmed"]["locations"][i]["country"]=="US":#判断美国数据
ussum=ussum+int(json_text["confirmed"]["locations"][i]["history"][date])
elif json_text["confirmed"]["locations"][i]["country"]=="China":#判断中国数据
#attr.append(json_text["confirmed"]["locations"][i]["province"])
chinasum=chinasum+int(json_text["confirmed"]["locations"][i]["history"][date])
elif json_text["confirmed"]["locations"][i]["country"]=="Canada":#判断加拿大数据
Canadasum=Canadasum+int(json_text["confirmed"]["locations"][i]["history"][date])
elif json_text["confirmed"]["locations"][i]["country"]=="United Kingdom":#判断英国数据
UKsum=UKsum+int(json_text["confirmed"]["locations"][i]["history"][date])
elif json_text["confirmed"]["locations"][i]["country"]=="Australia":#判断澳大利亚数据
Australiasum=Australiasum+int(json_text["confirmed"]["locations"][i]["history"][date])
elif json_text["confirmed"]["locations"][i]["country"]=="France":#判断法国数据
Francesum=Francesum+int(json_text["confirmed"]["locations"][i]["history"][date])
else:
attr.append(json_text["confirmed"]["locations"][i]["country"])
value.append(json_text["confirmed"]["locations"][i]["history"][date])
attr.append("China")
value.append(int(chinasum))
attr.append("United States")
value.append(int(ussum))
attr.append("Canada")
value.append(int(Canadasum))
attr.append("United Kingdom")
value.append(int(UKsum))
attr.append("Australia")
value.append(int(Australiasum))
attr.append("France")
value.append(int(Francesum))
print(value)
print(attr)
map0 = Map("世界地图示例", width=1200, height=600)
map0.add("世界新冠状病毒疫情地图", attr,value,
maptype="world",type='heatmap',is_visualmap=True,
visual_text_color='#000',
visual_range=[min(value), max(value)],
is_map_symbol_show=False,
label_text_size=0.5)
map0.render(path="新世界地图疫情情况.html")
#,is_label_show=True, 展示国家名称
下一篇: python numpy库详解