首页 > 解决方案 > 分割出图的峰峰值以获得1周期python

问题描述

import matplotlib.pyplot as plt
import numpy as np
import pdb

file = open("Data1r2.txt", 'r')
lines = file.readlines()
file.close()

所以我想要得到的是让代码使用 txt 文件中的数据并绘制图表。我坚持的是我无法弄清楚如何让峰值检测让图表显示峰值,因为我需要计算从一个峰值到另一个峰值的值。

t = []
z = []
y = []
x = []

for line in lines:

  parts = line.split(", ")
  if len(parts) > 3:
column1 = parts[3].split(':')
column2 = column1[1]

column3 = parts[2].split(':')
column4 = column3[1]

column5 = parts[1].split(':')
column6 = column5[1]

column7 = parts[0].split(':')
column8 = column7[1]

T = column2[0:len(column2)]
Z = column4[0:len(column4)]
Y = column6[0:len(column6)]
X = column8[0:len(column8)]

设置跟踪

T1 = float(T)
t.append(T1)

Z1 = float(Z)
z.append(Z1)

Y1 = float(Y)
y.append(Y1)

X1 = float(X)
x.append(X1)

绘制图表

  plt.plot(t,z,label='z')
  plt.plot(t,y,label='y')
  plt.plot(t,x,label='x')
  plt.legend()
  plt.show()

数据样本

图形

我希望能够在 1 个时期内将图表从峰到峰剪掉

标签: pythonnumpymatplotlib

解决方案


推荐阅读