from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
# 创建一个地图对象
map = Map()
# 准备数据
data = [
("北京市", 99),
("上海市", 199),
("湖南省", 399),
("广东省", 499)
]
# 添加数据
map = map.add("测试地图", data, "china")
# 设置全局选项
map.set_global_opts(
visualmap_opts=VisualMapOpts( # 地图视觉指示器
is_show=True,
is_piecewise=True, # 开启手动校准范围
pieces=[
{"min": 1, "max": 9, "label": "1-9", "color": "#CCFFFF"},
{"min": 10, "max": 99, "label": "10-99", "color": "#FF6666"},
{"min": 100, "max": 500, "label": "100-500", "color": "#990033"}
]
)
)
map.render()
import json
from pyecharts.charts import Map
from pyecharts.options import *
# 读取数据文件
f = open("D:/疫情.txt", "r", encoding="UTF-8")
data = f.read()
f.close()
# 将字符串json转换为python数据
data_dict = json.loads(data)
data_list = [] # 绘图需要的数据
province_data_list = data_dict["areaTree"][0]["children"]
for province_data in province_data_list:
province_name = province_data["name"]+"省" # 省份名称
province_confirm = province_data["total"]["confirm"] # 省份人数
data_list.append((province_name, province_confirm)) # 用了俩个括号
print(data_list)
# 创建地图对象
map = 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, "lable": "1-99人", "color": "#CCFFFF"},
{"min": 100, "max": 999, "lable": "100-999人", "color": "#FFFF99"},
{"min": 1000, "max": 4999, "lable": "1000-4999人", "color": "#FF9966"},
{"min": 5000, "max": 9999, "lable": "5000-9999人", "color": "#FF6666"},
{"min": 10000, "max": 99999, "lable": "10000-99999人", "color": "#CC3333"},
{"min": 100000 , "lable": "100000+", "color": "#990033"}
]
)
)
map.render("全国疫情地图.html")
import json
from pyecharts.charts import Map
from pyecharts.options import *
f = open("D:/疫情.txt", 'r', encoding="UTF-8")
data = f.read()
f.close()
data_dict = json.loads(data)
data_list = data_dict["areaTree"][0]["children"][3]["children"]
data_f = []
for data in data_list:
data_name = data["name"]+"市"
data_confirm = data["total"]["confirm"]
data_f.append((data_name,data_confirm))
map = Map()
map.add("河南疫情地图",data_f,"河南")
map.set_global_opts(
title_opts=TitleOpts(title="河南省疫情地图"),
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-999人", "color": "#FFFF99"},
{"min": 1000, "max": 4999, "lable": "1000-4999人", "color": "#FF9966"},
{"min": 5000, "max": 9999, "lable": "5000-9999人", "color": "#FF6666"},
{"min": 10000, "max": 99999, "lable": "10000-99999人", "color": "#CC3333"},
{"min": 100000 , "lable": "100000+", "color": "#990033"}
]
)
)
map.render("河南疫情地图.html",)