一、2D世界地图
代码
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
c = (
Map(init_opts=opts.InitOpts(width='1500px', height='1200px',bg_color='#E0EEEE'))
# 加载世界地图实例
.add("世界地图", [list(z) for z in zip(Faker.country, Faker.values())], "world")
# 不显示地图标志
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
# 配置项标题设置
title_opts=opts.TitleOpts(title="世界地图示例"),
visualmap_opts=opts.VisualMapOpts(max_=200)
)
# 生成超文本文件
.render("world_map.html")
)
效果图
二、中国3D地图
代码
from pyecharts import options as opts
from pyecharts.charts import Map3D
from pyecharts.globals import ChartType
c = (
Map3D(init_opts=opts.InitOpts(width='1300px', height='1300px',bg_color='#EBEBEB'))
.add_schema(
itemstyle_opts=opts.ItemStyleOpts(
color="#CDBA96",
opacity=1,
border_width=0.8,
border_color="rgb(62,215,213)",
),
map3d_label=opts.Map3DLabelOpts(
is_show=True,
text_style=opts.TextStyleOpts(
color="#104E8B", font_size=16, background_color="rgba(0,0,0,0)"
),
),
emphasis_label_opts=opts.LabelOpts(is_show=True),
light_opts=opts.Map3DLightOpts(
main_color="#FFEBCD",
main_intensity=1.2,
is_main_shadow=False,
main_alpha=55,
main_beta=10,
ambient_intensity=0.3,
),
)
.add(series_name="", data_pair="", maptype=ChartType.MAP3D)
# 全局设置地图属性
.set_global_opts(
title_opts=opts.TitleOpts(title="全国行政区划地图"),
visualmap_opts=opts.VisualMapOpts(is_show=False),
tooltip_opts=opts.TooltipOpts(is_show=True),
)
.render("map3d_china_base.html")
)
效果图
三、贵州地图
代码
# 写入省份内各地区经纬度
example_data = [
[[106.70722,26.59820, 1000],[106.63024, 26.64702, 1000]],
[[104.83023, 26.59336], [106.92723, 27.72545]],
[[105.30504, 27.29847], [107.52034, 26.29322]],
[[107.89868, 26.52881], [104.948571, 25.077502]],
[[105.9462, 26.25367], [109.18099, 27.69066]],
]
# 添加 3D 地图
c = (
Map3D(init_opts=opts.InitOpts(width='1200px', height='1200px'))
.add_schema(
maptype="贵州",
itemstyle_opts=opts.ItemStyleOpts(
color="rgb(5,101,123)",
opacity=1,
border_width=0.8,
border_color="rgb(62,215,213)",
),
light_opts=opts.Map3DLightOpts(
main_color="#fff",
main_intensity=1.2,
is_main_shadow=True,
main_alpha=55,
main_beta=10,
ambient_intensity=0.3,
),
view_control_opts=opts.Map3DViewControlOpts(center=[-10, 0, 10]),
post_effect_opts=opts.Map3DPostEffectOpts(is_enable=True),
)
.add(
series_name="",
data_pair=example_data,
type_=ChartType.LINES3D,
effect=opts.Lines3DEffectOpts(
is_show=True,
period=4,
trail_width=3,
trail_length=0.5,
trail_color="#f00",
trail_opacity=1,
),
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Map3D-GuiZhou3D"))
.render("guizhou_map_3d.html")
)
效果图
四、地球村
代码
import pyecharts.options as opts
from pyecharts.charts import MapGlobe
from pyecharts.faker import POPULATION
data = [x for _, x in POPULATION[1:]]
low, high = min(data), max(data)
c = (
MapGlobe(init_opts=opts.InitOpts(width='1000px', height='1000px',bg_color='#FFFAFA',))
.add_schema()
.add(
maptype="world",
series_name="World Population",
data_pair=POPULATION[1:],
is_map_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="3D 地球示例"),
# 设置地球属性
visualmap_opts=opts.VisualMapOpts(
min_=low,
max_=high,
range_text=["max", "min"],
is_calculable=True,
range_color=["lightskyblue", "yellow", "orangered"],
)
)
.render("world_map_3d.html")
)
效果图
参考:https://gallery.pyecharts.org/#/Map3D/README
"一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少