pyecharts对于经纬度_pyecharts动态轨迹图的实现示例
时间: 2023-11-15 10:03:25 浏览: 252
以下是一个使用 Pyecharts 实现经纬度动态轨迹图的示例代码:
```python
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Geo, Timeline
# 读取数据
data = pd.read_csv('data.csv')
# 创建时间轴
timeline = Timeline()
# 创建地理图
geo = Geo(init_opts=opts.InitOpts(width='1000px', height='600px'))
# 遍历数据
for i, row in data.iterrows():
# 添加时间点
timeline.add(
geo.add_schema(
maptype='world',
center=[row['lon'], row['lat']],
zoom=4,
).add_coordinate(
row['name'], row['lon'], row['lat'],
).add(
row['name'], [(row['lon'], row['lat'])],
type_='scatter',
symbol_size=8,
label_opts=opts.LabelOpts(is_show=False),
itemstyle_opts=opts.ItemStyleOpts(color='red'),
).set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
).set_global_opts(
title_opts=opts.TitleOpts(
title='动态轨迹图',
subtitle=f'{row["time"]}',
pos_left='20%',
),
visualmap_opts=opts.VisualMapOpts(
min_=0,
max_=100,
is_piecewise=True,
pieces=[
{'min': 0, 'max': 20, 'label': '0-20'},
{'min': 20, 'max': 40, 'label': '20-40'},
{'min': 40, 'max': 60, 'label': '40-60'},
{'min': 60, 'max': 80, 'label': '60-80'},
{'min': 80, 'max': 100, 'label': '80-100'},
],
),
),
f'{row["time"]}',
)
# 渲染图像
timeline.render('timeline_geo.html')
```
其中,`data.csv` 是包含数据的 CSV 文件,示例数据如下:
```
name,time,lat,lon
New York,2022-01-01 00:00:00,40.712776,-74.005974
Beijing,2022-01-01 01:00:00,39.904200,116.407396
Sydney,2022-01-01 02:00:00,-33.865143,151.209900
Paris,2022-01-01 03:00:00,48.856613,2.352222
```
运行代码后,将会生成 `timeline_geo.html` 文件,用浏览器打开即可查看动态轨迹图。
阅读全文