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

运行

在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐