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

如何从同层级多条等高线中选择单条23℃等高线路径

提取单条23℃等高线路径的方法

核心思路

plt.contour()返回的contour对象中,get_paths()会返回所有独立的等高线路径(每条路径对应一个Path实例)。你可以通过路径的顶点范围、长度或直接可视化区分的方式,筛选出目标单条路径。

具体实现步骤

  1. 排查所有路径的基本特征
    遍历所有路径,打印每条路径的顶点数、时间/深度范围,快速定位目标路径:
for idx, path in enumerate(paths):
    verts = path.vertices
    print(f"路径{idx}: 顶点数={len(verts)}, 时间范围={verts[:,0].min()}-{verts[:,0].max()}, 深度范围={verts[:,1].min()}-{verts[:,1].max()}")
  1. 按业务特征筛选目标路径
    如果目标23℃等高线是覆盖完整时间序列的连续线,它的时间范围会和原始数据的时间区间基本一致,用这个特征筛选:
# 获取原始数据的完整时间范围
full_time_min = ds.TIME1.min()
full_time_max = ds.TIME1.max()

target_path = None
for path in paths:
    verts = path.vertices
    # 用极小误差避免浮点精度问题
    if (verts[:,0].min() <= full_time_min + 1e-5) and (verts[:,0].max() >= full_time_max - 1e-5):
        target_path = path
        break

# 提取目标路径的顶点
if target_path:
    target_vertices = target_path.vertices
  1. 可视化验证路径(可选)
    如果不确定哪条是目标,把所有路径用不同颜色画出,直观区分:
import matplotlib.pyplot as plt
colors = ['#ff4444', '#0099cc', '#77dd77', '#ffaa33']
for idx, path in enumerate(paths):
    verts = path.vertices
    plt.plot(verts[:,0], verts[:,1], color=colors[idx % len(colors)], label=f'Path {idx}')
plt.legend()
plt.xlabel('TIME1')
plt.ylabel('DEPTH')
plt.show()

额外提示

  • 若数据中存在孤立的23℃小区域,会生成闭合的短路径,这类路径的顶点数少、时间/深度范围窄,很容易和主路径区分。
  • 顶点数量多是正常现象(保证等高线平滑),如果需要精简顶点,可使用target_path.simplify(tolerance=0.1)(tolerance值越大,精简后的顶点越少)。

内容的提问来源于stack exchange,提问作者Ranjan Kumar Sahu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 18:07:24