一、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://mp.weixin.qq.com/s?__biz=MzUyOTk2MTcwNg==&mid=2247489251&idx=1&sn=ee48d73cfe27e222c03e9e7f6f914568&chksm=fa585166cd2fd870cf218767612e39d365ec0847614ccc91a990a5a2d6f23fa3127cf3a6c83b&scene=126&sessionid=1611794067&key=17fda4f84bd4403138da1dfa2fbca071b0fbf84ae9e0f6ef84cb7df86d7731dcdc775adc8aa6646d01bc21a362edd82a738109d920328bcde920cf596dfcab5e021bc5fc73189540b1db6ddc31d0b1ca8002af16cb81f7320a5ccb7773789b0f7df9b3f95e55e6bcd5ca241cc986e3d62a8882306c506d80d5ace361f5b93f84&ascene=1&uin=MjM3MjczMTM2MQ%3D%3D&devicetype=Windows+10+x64&version=6300002f&lang=zh_CN&exportkey=ASpo8%2Bixao4Ke4dpgft6qqY%3D&pass_ticket=Gwod90cS0OFiBskAQSWJiXTZnJNTrI%2FyuOzsthC6wqttHIlg4dcWSi%2FXlIS%2Bhjn4&wx_header=0
參考:https://gallery.pyecharts.org/#/Map3D/README