Python实例pyechart的应用疫情地图构建

该程序从一个名为疫情.txt的JSON文件中读取数据,处理并过滤出中国各省份(包括特别行政区)的疫情确诊人数。利用pyecharts库,将这些数据映射到中国地图上进行可视化,不同颜色表示不同确诊人数范围。
摘要由CSDN通过智能技术生成

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

运行

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值