注:本文所用数据均来自百度开源数据
Admin_Log
数据会在下方展示下载按钮,请自行提取。
本文需要用到json、pyecharts模块,请自行在PyCharm中添加,因数据中为展示莱芜和东营地区数据,本文中含有添加数据。
图表演示链接:Epidemic-Map-of-ShanDong – Admin_Log加载可能较慢,请耐心等待◊ヾ(•ω•`)o
代码块:
import json from pyecharts.charts import Map from pyecharts.options import * # 读取数据文件 f = open("E:/PycharmProjects/可视化案例数据/地图数据/疫情.txt", "r", encoding="UTF-8") data = f.read() # 关闭文件 f.close() # 将json数据转python字典 data_dict = json.loads(data) # 取山东数据 cities_data = data_dict["areaTree"][0]["children"][11]["children"] # 准备数据为元组并放入list data_list = [] for city_data in cities_data: city_name = city_data["name"] + "市" print(city_name) city_confirm = city_data["total"]["confirm"] data_list.append((city_name, city_confirm)) # print(data_list) # 手动添加数据 data_list.append(("莱芜市", 24)) data_list.append(("东营市", 13)) # 构建地图 map = Map() map.add("山东省疫情分布", data_list, "山东") # 设置全局配置,定制分段的视觉映射 map.set_global_opts( title_opts=TitleOpts(title="全国疫情地图"), 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 -4 999人", "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")