用pyecharts画地图(世界地图、中国省级地图、市级地图、某省市级地图、某市县级地图
pyecharts-世界地图
from pyecharts.charts import Map # 注意这里与老版本pyecharts调用的区别
from pyecharts import options as opts
import random
country = ['China', 'Canada', 'France', 'Japan', 'Russia', 'USA']
data_world = [(i, random.randint(100, 200)) for i in country]
world = (
Map()
.add('', # 此处没取名,所以空着
data_world, # 数据
'world') # 地图类型
.set_global_opts(
title_opts=opts.TitleOpts(title='World Map'),
visualmap_opts=opts.VisualMapOpts(
max_=200,
min_=100,
is_piecewise=True) # 定义图例为分段型,默认为连续的图例
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.render(path='世界地图.html')
)
pyecharts-中国省级地图
province = ['广东', '湖北', '湖南', '四川', '重庆', '黑龙江', '浙江', '山西']
data_province = [(i, random.randint(100, 200)) for i in province]
# print(data)
china_province = (
Map()
.add('', data_province, 'china')
.set_global_opts(
title_opts=opts.TitleOpts(title='Provinces of China'),
visualmap_opts=opts.VisualMapOpts(
min_=100,
max_=200,
is_piecewise=True)
)
.render(path='中国省级地图.html')
)
pyecharts-中国市级地图
city = ['北京', '天津', '上海', '广州', '阿拉善盟', '株洲']
data_city = [(i, random.randint(100, 200)) for i in city]
china_city = (
Map()
.add(
"",
data_city,
"china-cities",
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="中国市级地图"),
visualmap_opts=opts.VisualMapOpts(
min_=100,
max_=200,
is_piecewise=True
),
)
.render("中国地级市地图.html")
)
pyecharts-某省市级地图
prov_city = ['长沙市', '株洲市', '湘潭市', '衡阳市']
data_prov_city = [(i, random.randint(100, 200)) for i in prov_city]
province_city = (
Map()
.add("",
data_prov_city,
"湖南")
.set_global_opts(
title_opts=opts.TitleOpts(title="某省地级市地图"),
visualmap_opts=opts.VisualMapOpts(
min_=100,
max_=200,
is_piecewise=True
)
)
.render(path="某省地级市地图.html")
)
pyecharts-某市县级地图
counties = (
Map()
.add(
"",
[['博罗县', 100]],
"惠州",
label_opts=opts.LabelOpts(is_show=False)
)
.set_global_opts(
title_opts=opts.TitleOpts(title="中国某市区县地图"),
visualmap_opts=opts.VisualMapOpts(),
)
.render("某市的区县地图.html")
)