官方文檔
簡介 - pyecharts - A Python Echarts Plotting Library built with love.
先繪制個3D地圖
import pyecharts.options as opts
from pyecharts.charts import Map3D
from pyecharts.globals import ChartType
map3d = (
# 3D地圖
Map3D(
# 初始化配置項
init_opts=opts.InitOpts(
theme='dark', # 圖表主題 white dark
width='99vw', # 圖表畫布寬度
height='97vh', # 圖示畫布長度
)
)
# !!!!全局配置項!!!!
.set_global_opts(
# 标題配置項
title_opts=opts.TitleOpts(
title="3D地圖+3D路徑圖", # 主标題
),
)
.add_schema(
# 地圖類型
maptype='china',
# 圖元樣式配置項
itemstyle_opts=opts.ItemStyleOpts(
# 圖形的顔色
color="#1661AB",
# 描邊寬度,預設不描邊。
border_width=0.8,
# 圖形的描邊顔色。支援的顔色格式同 color,不支援回調函數。
border_color="rgb(62,215,213)"
),
)
)
map3d.render("test5.html")
運作一下看下結果
再添加個3D路徑圖
import pyecharts.options as opts
from pyecharts.charts import Map3D
from pyecharts.globals import ChartType
# 定義變量
data_pair = [
[(113.2700, 23.1300), (118.8062, 31.9208)], [(125.8154, 44.2584), (87.9236, 43.5883)],
[(117.4219, 39.4189), (108.3843, 30.4397)], [(91.1100, 29.9700), (103.9526, 30.7617)],
[(108.4790, 23.1152), (117.2900, 32.0581)], [(113.0823, 28.2568), (110.3893, 19.8516)],
[(101.4038, 36.8207), (119.4543, 25.9222)], [(116.0046, 28.6633), (110.3467, 41.4899)],
]
map3d = (
# 3D地圖
Map3D(
# 初始化配置項
init_opts=opts.InitOpts(
theme='dark', # 圖表主題 white dark
width='99vw', # 圖表畫布寬度
height='97vh', # 圖示畫布長度
)
)
# !!!!全局配置項!!!!
.set_global_opts(
# 标題配置項
title_opts=opts.TitleOpts(
title="3D地圖+3D路徑圖", # 主标題
),
)
.add_schema(
# 地圖類型
maptype='china',
# 圖元樣式配置項
itemstyle_opts=opts.ItemStyleOpts(
# 圖形的顔色
color="#1661AB",
# 描邊寬度,預設不描邊。
border_width=0.8,
# 圖形的描邊顔色。支援的顔色格式同 color,不支援回調函數。
border_color="rgb(62,215,213)"
),
)
# 資料配置
.add(
# 系列名稱,用于 tooltip 的顯示,legend 的圖例篩選
series_name='航班',
# 資料項 (坐标點名稱,坐标點值)
data_pair=data_pair,
# 疊加圖的類型(目前隻支援 Bar3D,Line3D,Lines3D,Scatter3D)
type_=ChartType.LINES3D,
# 僅在 Lines3D 起作用
# 飛線的尾迹特效,參考 `series_options.Line3DEffectOpts`
effect=opts.Lines3DEffectOpts(
# 是否顯示尾迹特效,預設不顯示。
is_show=True,
# 尾迹特效的周期。
period=4,
# 尾迹的寬度。
trail_width=3,
# 尾迹的長度,範圍從 0 到 1,為線條長度的百分比
trail_length=0.5,
# 尾迹的顔色,預設跟線條顔色相同。
trail_color="white",
# 尾迹的不透明度,預設跟線條不透明度相同
trail_opacity=1,
),
# 僅在 Line3D,Lines3D 起作用
# 飛線的線條樣式,參考 `series_options.LineStyleOpts`
linestyle_opts=opts.LineStyleOpts(
# 是否顯示
is_show=True,
# 線寬
width=3,
# 圖形透明度。支援從 0 到 1 的數字,為 0 時不繪制該圖形
opacity=0.5,
# 線的顔色
color="lightgreen",
),
)
)
map3d.render("test5.html")
再運作一下看下結果
以上就是3D地圖+3D路徑圖的繪制,不懂的可以看一下之前的部落格,更多配置請移至官方文檔。
Python pyecharts 快速入門_小豬小豬呼噜噜的部落格-CSDN部落格