首页 > 解决方案 > 从带有水平线的 .txt 文件中提取相交值

问题描述

我有一组来自 .txt 文件的数据,我能够成功地在我的 python 脚本上绘制这些数据。现在我想添加两条水平线(y=1.5 和 y=3),当它们与轮廓相交时,它会为我提供该 y 值的所有信息,因此对于每个轮廓,我应该有两行信息(一个对于 y=1.5 和 y=3)。有没有快速的方法呢? 配置文件中的数据

这是我到目前为止的代码:

import glob
import pandas as pd
import matplotlib.pyplot as plt
files = glob.glob('*.txt')
 
profiles = []
for file in files:
    data = pd.read_csv(file, skiprows = [1], sep = '\t', index_col = False, engine='python')
    profiles.append(data)

fig, ax = plt.subplots()
 
for profile in profiles:
    z = profile['Z_ZH']
    d = profile['DIST_CP']
    ax.plot(d, z, label = profile['Data'][0])
 
ax.legend()

我正在使用的配置文件

标签: python

解决方案


推荐阅读