注:本文所用数据均来自百度开源数据
数据会在下方展示下载按钮,请自行提取。
本文需要用到jsonpyecharts模块,请自行在PyCharm中添加
图标演示链接:Epidemic map – Admin_Log加载可能较慢,请耐心等待◊ヾ(•ω•`)o

Admin_Log

问题描述
该数据各省份数据中均不带“”和“”以及“XX自治区”、“XX特别行政区”,本人计划将数据做统一处理,奈何技术不精,未能将数据到处至文本文档,只能暂时将数据保存到该项目中。
希望各位大佬有意请帮忙修改数据,本人在此谢过(✿◡‿◡)
[ 项目文本在下载中可获取 ]

Admin_Log

import json
from pyecharts.charts import Map
from pyecharts.options import *

# 读取数据文件
f = open("E:/PycharmProjects/可视化案例数据/地图数据/疫情2.txt", "r", encoding="UTF-8")
# fw = open("E:/PycharmProjects/可视化案例数据/地图数据/疫情2.bak.txt", "w", encoding="UTF-8")
data = f.read()
# 关闭文件
f.close()

# 去到各省数据
# 将字符串json转换为python的字典
data_dict = json.loads(data)   # 基础数据字典
# print(data_dict)

# 从字典中取出省份的数据
province_data_list = data_dict["areaTree"][0]["children"]
# print(province_data_list)
data_list = []
for province_data in province_data_list:
    province_name = province_data["name"]
    province_name += "省"
    # print(province_name)
    if province_name == "北京省":
        province_name = "北京市"
    elif province_name == "天津省":
        province_name = "天津市"
    elif province_name == "上海省":
        province_name = "上海市"
    elif province_name == "重庆省":
        province_name = "重庆市"
    elif province_name == "内蒙古省":
        province_name = "内蒙古自治区"
    elif province_name == "广西省":
        province_name = "广西壮族自治区"
    elif province_name == "西藏省":
        province_name = "西藏自治区"
    elif province_name == "宁夏省":
        province_name = "宁夏回族自治区"
    elif province_name == "新疆省":
        province_name = "新疆维吾尔自治区"
    elif province_name == "香港省":
        province_name = "香港特别行政区"
    elif province_name == "澳门省":
        province_name = "澳门特别行政区"
    print(province_name)
    province_confirm = province_data["total"]["confirm"]
    data_list.append((province_name, province_confirm))
    # print(data_list)
# 创建地图对象
map = Map()
# 添加数据
map.add("各省份确诊人数", data_list, "china")
# 设置全局配置,定制分段的视觉映射
map.set_global_opts(
    title_opts=TitleOpts(title="全国疫情地图"),
    visualmap_opts=VisualMapOpts(
        is_show=True,       # 是否显示
        is_piecewise=True,  # 是否分段
        pieces=[
            {"min": 1, "max": 99, "label": "1-9人", "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, "lable": "10000+", "color": "#990033"}
        ]
    )
)
# 绘图
map.render("全国疫情地图.html")

查看信息

  • 数据查看地址:查看数据点击查看 Json 数据[ 默认编码UTF-8 若乱码请自行切换编码格式 ]

Admin_Log