"""
河南省疫情地图开发
"""
import json
from pyecharts.charts import Map
from pyecharts.options import *
#读取文件
f=open("J:/疫情.txt","r",encoding="UTF-8")
data=f.read()
#关闭文件
f.close()
#获取河南省数据
dict=json.loads(data)
cities_data=dict["areaTree"][0]["children"][3]["children"]
#准备数据为元组并放入list
data_list=[]
for city_data in cities_data:
city_name=city_data["name"]
city_confirm=city_data["total"]["confirm"]
data_list.append((city_name,city_confirm))
data_list.append(("济源市",5))
#构建地图
map=Map()
map.add("河南省疫情分布",data_list,"河南")
#设置全局选项
map.set_global_opts(
title_opts=TitleOpts("河南省疫情地图"),
visualmap_opts=VisualMapOpts(
is_show=True, # 是否显示
is_piecewise=True, # 是否分段
pieces=[
{"min": 1, "max": 99, "lable": "1~99人", "color": "#CCFFFF"},
{"min": 100, "max": 999, "lable": "100~9999人", "color": "#FFFF99"},
{"min": 1000, "max": 4999, "lable": "1000~4999人", "color": "#FF9966"},
{"min": 5000, "max": 9999, "lable": "5000~99999人", "color": "#FF6666"},
{"min": 10000, "max": 99999, "lable": "10000~99999人", "color": "#CC3333"},
{"min": 100000, "lable": "100000+", "color": "#990033"},
]
)
)
#绘图
map.render()
python——河南省疫情地图开发
最新推荐文章于 2024-04-28 02:41:51 发布