在【生成图片展示】博客的基础上,进一步的确定某个省份的数据。
# 以下数据均为人造数据,仅供学习
# 1.导包
from pyecharts.options import *
from pyecharts.charts import Map
import json
# 2.打开、读取、关闭文件
f = open("D:/Typora 记事本/notebook/Python/Exercise_data/疫情.txt","r",encoding="UTF-8")
data = f.read()
f.close()
# 3.获取某个省份的数据(以广东省为例)
data_dict = json.loads(data)
# 4.从字典数据中,获取具体广东省数据
city_GD_list = data_dict['areaTree'][0]['children'][7]['children']
# 5.利用循环语句,存放广东省下每个市的数据
data_list = [] #设置空列表,存放数据
for i in city_GD_list:
province_GdName = i['name'] + '市'
province_GdConfirm = i['total']['confirm']
data_list.append((province_GdName,province_GdConfirm))
# 6.生成地图对象
map = Map()
map.add("广东省疫情分布",data_list,"广东")
# 7.设置全局变量
map.set_global_opts(
title_opts=TitleOpts(title="广东省疫情分布数据"),
visualmap_opts=VisualMapOpts(
is_show=True,
is_piecewise=True,
pieces=[
{"min":1,"max":49,"label":"1-49人","color":"#CCFFF"},
{"min":50,"max":99,"label":"50-99人","color":"#FFFF99"},
{"min":100,"max":199,"label":"100-199人","color":"#FF9966"},
{"min":200,"label":"200人以上","color":"#cc3333"},
]
)
)
# 8.绘图
map.render()