import json
from pyecharts.charts import Map
from pyechart.options import *
map = Map()
f = open("D:/Typora 记事本/notebook/Python/Exercise_data/疫情.txt","r",encoding="UTF-8")
data = f.read()
f.close()
data_dict = json.loads(data)
province_data_list = data_dict["areaTree"][0]["children"]
data_list = []
for i in province_data_list:
province_name = i['name']
province_confirm = i['total']['confirm']
data_list.append((province_name,province_confirm))
map.add("各省份确诊人数",data_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": "#CC3333"},
{"min": 10000, "label": "10000人以上", "color": "#990033"}
]
)
)
map.render("确诊人数.html")
效果图: