You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python可视化Kedarkantha徒步GPX文件的海拔与路线数据?

生成Kedarkantha徒步路线海拔剖面图(Elevation vs Distance)

我用GPS追踪应用记录了Kedarkantha徒步行程,该应用导出了一个.gpx文件,希望创建一个展示海拔 vs 距离的折线图,可视化徒步路线的剖面图。

以下是实现代码:

import gpxpy
import matplotlib.pyplot as plt

with open("kedarkantha.gpx", "r") as f:
    gpx = gpxpy.parse(f)

elevations = []
distances = []

for track in gpx.tracks:
    for segment in track.segments:
        prev_point = None
        total_distance = 0
        for point in segment.points:
            if prev_point:
                # 计算当前点与上一点的3D距离并累加
                total_distance += point.distance_3d(prev_point)
            elevations.append(point.elevation)
            distances.append(total_distance)
            prev_point = point

# 绘制海拔剖面图
plt.plot(distances, elevations)
plt.xlabel("距离 (米)")
plt.ylabel("海拔 (米)")
plt.title("Kedarkantha徒步路线海拔剖面图")
plt.show()

代码说明:

  • 使用gpxpy库读取并解析GPX文件,提取轨迹中的所有点位信息
  • 遍历轨迹分段,逐点计算累计3D距离(考虑海拔变化的真实徒步距离)
  • 用matplotlib绘制折线图,直观展示徒步过程中海拔随距离的变化趋势

内容的提问来源于stack exchange,提问作者Himalayan Hikers

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 02:22:32