如何找到以下峰的y值

时间:2019-05-19 21:56:20

标签: python scipy

import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
from scipy.signal import find_peaks
x = electrocardiogram()[2000:4000]
peaks, _ = find_peaks(x, height=1)
plt.plot(x)
plt.plot(peaks, x[peaks], "x")
plt.plot(np.zeros_like(x), "--", color="gray")
print(peaks)
plt.show()

在下面的程序中,峰是通过scipy计算的,但是当我打印峰的值时,唯一出现的值是沿x轴...有没有办法沿x轴打印峰的值和y轴,以便在(x,y)坐标中完成信息。.

1 个答案:

答案 0 :(得分:0)

您可以使用

import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
from scipy.signal import find_peaks
x = electrocardiogram()[2000:4000]
peaks, _ = find_peaks(x, height=1)
plt.plot(x)
plt.plot(peaks, x[peaks], "x")
plt.plot(np.zeros_like(x), "--", color="gray")
print( [(i,j) for i, j in zip(peaks, x[peaks] )] )  # To print x and corresponding peak at x
plt.show()