- 2D 세계지도 생성
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
world_map = (
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("global_map.html")
)
이 코드는 전 세계 국가의 가상 데이터를 기반으로 2D 지도를 렌더링합니다.
- 중국 3D 행정 구역 지도
from pyecharts import options as opts
from pyecharts.charts import Map3D
from pyecharts.globals import ChartType
china_3d_map = (
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="중국 행정구역 3D 지도"),
visualmap_opts=opts.VisualMapOpts(is_show=False),
tooltip_opts=opts.TooltipOpts(is_show=True),
)
.render("china_map3d.html")
)
- 귀주성 3D 지도 표현
example_coordinates = [
[[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]],
]
guizhou_3d = (
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_coordinates,
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="귀주성 3D 경로 지도"))
.render("guizhou_lines3d.html")
)
- 3D 지구 시각화 (지구촌)
import pyecharts.options as opts
from pyecharts.charts import MapGlobe
from pyecharts.faker import POPULATION
population_data = [x for _, x in POPULATION[1:]]
min_val, max_val = min(population_data), max(population_data)
earth_globe = (
MapGlobe(init_opts=opts.InitOpts(width='1000px', height='1000px', bg_color='#FFFAFA'))
.add_schema()
.add(
maptype="world",
series_name="세계 인구 분포",
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_=min_val,
max_=max_val,
range_text=["최대", "최소"],
is_calculable=True,
range_color=["lightskyblue", "yellow", "orangered"],
)
)
.render("earth_population.html")
)