我的数据文件在以下链接中共享。
我们可以使用以下脚本绘制此数据。
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
def read_datafile(file_name):
data = np.loadtxt(file_name, delimiter=',')
return data
data = read_datafile('mah_data.csv')
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_title("Data")
ax1.set_xlabel('t')
ax1.set_ylabel('s')
ax1.plot(x,y, c='r', label='My data')
leg = ax1.legend()
plt.show()
我们如何检测 python 中的峰值?我在 Python 中找不到合适的峰值检测算法。
最佳答案
您可以使用 scipy.signal 中的 argrelextrema 函数返回数组的局部最大值或局部最小值的索引。通过指定轴,这也适用于多维数组。
from scipy.signal import argrelextrema
ind_max = argrelextrema(z, np.greater) # indices of the local maxima
ind_min = argrelextrema(z, np.less) # indices of the local minima
maxvals = z[ind_max]
minvals = z[ind_min]
更具体地说,可以使用argrelmax 或argrelmin 来找到局部最大值或局部最小值。这也适用于使用轴参数的多维数组。
from scipy.signal import argrelmax, argrelmin
ind_max = argrelmax(z, np.greater) # indices of the local maxima
ind_min = argrelmin(z, np.less) # indices of the local minima
maxvals = z[ind_max]
minvals = z[ind_min]
更多详情,可引用此链接:https://docs.scipy.org/doc/scipy/reference/signal.html#peak-finding
关于python - 检测 python 图中的峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44466310/