官方文档
简介 - 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")
运行一下看下结果
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLlVWMhRWZkRmMmVDNkRmNhRTO2QzN5UTN4UzNkZTNiZ2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
再添加个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博客