python用pychart库,实现将经纬度信息在地图上显示

python使用pyecharts对给到的经纬度数据进行位置标注,下面是批量更新。给入数据,将地图生成。实验数据在下面附件。

from pyecharts import options as opts
from pyecharts.charts import Geo
import os

folder_path = 'F:\\GPS'
file_names = os.listdir(folder_path)
for file_name in file_names:
    geo_chart = Geo()
    open_path = folder_path+"\\"+file_name
    geo_chart.add_schema(maptype="china")
    with open(open_path, "r") as file:
        lines = [line.strip() for line in file.readlines()]

    points = [eval(line) for line in lines]

    for i, point in enumerate(points):
        geo_chart.add_coordinate(str(i), point[0], point[1])
    geo_chart.set_global_opts(
        title_opts=opts.TitleOpts(title="中国地图标记经纬度点"),
        visualmap_opts=opts.VisualMapOpts(max_=10),
    )

    for i, point in enumerate(points):
        geo_chart.add("", [(str(i), 1)])
    geo_chart.set_series_opts(
        effect_opts=opts.EffectOpts(symbol="circle", symbol_size=8, color="blue"),
        label_opts=opts.LabelOpts(is_show=False),
    )
    save_path = "F:\\GPS\\"+file_name[:-4]+".html"
    geo_chart.render(save_path)
    file.close()
    print(save_path)

结果:

在这里插入图片描述

资源内容如下:
在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个使用 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` 文件,用浏览器打开即可查看动态轨迹图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

如鸿毛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值