地图可视化
- 1.基础地图使用
-
- 2.全国疫情地图
-
- 2.1数据整理
- 2.2创建地图并添加数据
- 2.3设置全局配置
- 3.省级疫情图
1.基础地图使用
1.1基础地图演示
from pyecharts.charts import Map
map = Map()
data = [
("北京市",99),
("上海市",199),
("湖南省",299),
("台湾省",199),
("安徽省",299),
("广州省",399),
("湖北省",599)
]
map.add("地图",data,"china")
map.render("基础地图.html")
1.2视觉映射器
from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
map = Map()
data = [
("北京市",99),
("上海市",199),
("湖南省",299),
("台湾省",199),
("安徽省",299),
("广州省",399),
("湖北省",599)
]
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("基础地图.html")
2.全国疫情地图
2.1数据整理
import json
f = open("D:/疫情.txt","r",encoding="UTF-8")
data = f.read()
f.close()
data_dict = json.loads(data)
data_dict = json.loads(data)
province_data_list = data_dict["areaTree"][0]["children"]
data_list = []
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))
2.2创建地图并添加数据
map = Map()
map.add("各省份确诊人数",data_list,"china")
2.3设置全局配置
map.set_global_opts(
title_opts=TitleOpts(title="全国疫情图"),
visualmap_opts=VisualMapOpts(
is_show=True,
is_piecewise=True,
pieces=[
{"min":1,"max":9,"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,"label":"100000+","color":"#990033"},
]
)
)
map.render("全国疫情地图.html")
3.省级疫情图
import json
from pyecharts.charts import Map
from pyecharts.options import *
f = open("D:/疫情.txt","r",encoding="UTF-8")
data = f.read()
data = json.loads(data)
Tianjin_data_list = data["areaTree"][0]["children"][13]["children"]
data_list = []
for Tianjin_data in Tianjin_data_list:
name = Tianjin_data["name"]
confirm = Tianjin_data["total"]["confirm"]
data_list.append((name,confirm))
print(data_list)
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":9,"label":"1-9","color":"#CCFFFF"},
{"min":10,"max":99,"label":"100-999","color":"#FFFF99"},
{"min":100,"max":500,"label":"1000-4999","color":"#FF9966"},
{"min":501,"max":999,"label":"5000-9999","color":"#FF6666"},
{"min":10000,"label":"10000-99999","color":"#CC3333"}
]
)
)
map.render("省级疫情地图.html")