json数据
疫情.txt
https://pan.baidu.com/s/1E7yZzduTkcnA21uIDiAnKw?pwd=2i0l
提取码:2i0l
程序
import json
from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
total_list = []
f = open("D:/疫情.txt", "r", encoding="UTF-8")
data = f.read()
f.close()
py_data = json.loads(data)["areaTree"][0]["children"]
for i in py_data:
if i["name"] == "内蒙古":
i["name"] += "自治区"
total_list.append((i["name"],i["total"]["confirm"]))
elif i["name"] == "西藏":
i["name"] += "自治区"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "新疆":
i["name"] += "维吾尔自治区"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "宁夏":
i["name"] += "回族自治区"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "广西":
i["name"] += "壮族自治区"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "重庆":
i["name"] += "市"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "北京":
i["name"] += "市"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "天津":
i["name"] += "市"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "上海":
i["name"] += "市"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "香港":
i["name"] += "特别行政区"
total_list.append((i["name"], i["total"]["confirm"]))
elif i["name"] == "澳门":
i["name"] += "特别行政区"
total_list.append((i["name"], i["total"]["confirm"]))
else:
total_list.append((i["name"]+"省",i["total"]["confirm"]))
print(total_list)
map = Map()
map.add("各省疫情确诊人数",total_list,"china")
map.set_global_opts(
visualmap_opts=VisualMapOpts(
is_show=True,
is_piecewise=True,
pieces=[
{"min": 1,"max": 99,"label": "1-99", "color": "#CCFFFF"},
{"min": 100,"max": 999,"label": "100-999", "color": "#FFFF99"},
{"min": 1000,"max": 4999,"label": "1000-4999", "color": "#FF9966"},
{"min": 5000,"max": 9999,"label": "5000-9999", "color": "#FF6666"},
{"min": 10000,"max": 99999,"label": "10000-99999", "color": "#CC3333"},
{"min": 100000,"label": "100000+", "color": "#990033"}
]
)
)
map.render("全国疫情地图.html")