from pyecharts.charts import Map
from pyecharts import options
# 准备地图对象
map = Map()
# 准备数据,注意准备的数据必须是准确的,比如北京智能写北京市,湖南只能写湖南省,香港只能写香港特别行政区,西藏只能写西藏自治区等等,否则会出现数据不显示问题。
data = [("北京市", 100), ("上海市", 199), ("湖南省", 299), ("台湾省", 199), ("安徽省", 299), ("广州省", 399),
("湖北省", 599)]
# 添加数据(地图名称 地图数据 地图类型(默认))
map.add("测试地图", data, "china")
"""
设置全局变量
VisualMapOpts:视觉映射配置项
is_show: bool = True,是否显示视觉映射配置
is_piecewise: bool = False,是否为分段型
pieces:
[
{"min": 1500}, // 不指定 max,表示 max 为无限大(Infinity)。
{"min": 900, "max": 1500},
{"min": 310, "max": 1000},
{"min": 200, "max": 300},
{"min": 10, "max": 200, "label": '10 到 200(自定义label)'},
{"value": 123, "label": '123(自定义特殊颜色)', "color": 'grey'}, //表示 value 等于 123 的情况
{"max": 5} // 不指定 min,表示 min 为无限大(-Infinity)。
]
"""
map.set_global_opts(
visualmap_opts=options.VisualMapOpts(
is_show=True, is_piecewise=True,
pieces=[
{"min": 1, "max": 9, "label": "1-9人", "clor": "#CCFFFF"},
{"min": 10, "max": 99, "label": "10-99人", "clor": "#FFFF99"},
{"min": 100, "max": 499, "label": "100-499人", "clor": "#FF9966"},
{"min": 500, "max": 999, "label": "500-999人", "clor": "#CC666"},
{"min": 1000, "label": "1000人以上", "clor": "#990033"}
]
)
)
# 生成地图
map.render("map_test.html")