from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
# 准备地图对象
map = Map()
f = open("e:/1.txt", "r", encoding="UTF-8")
all_data = f.readlines()
f.close()
content = []
for line in all_data:
line = line.strip()
city = line.split(" ")[0]
num = line.split(" ")[1]
s1 = (city, num)
content.append(s1)
# print(content)
data = content
# 添加数据
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": 29, "label": "10-29", "color": "#FFFF99"},
{"min": 30, "max": 49, "label": "30-49", "color": "#FF9966"},
{"min": 50, "max": 79, "label": "50-79", "color": "#FF6666"},
{"min": 80, "max": 99, "label": "80-99", "color": "#CC3333"},
{"min": 100, "max": 199, "label": "100+", "color": "#990033"}
]
)
)
# 绘图
map.render("云钞征信机全国分布图.html")
1.txt文件为从EXCEL中复制出来的数据,下次可以测试一下将EXCEL转为.CVS文件看看效果