找到5个局部最大值和最小值点加上python中的极值

时间:2015-10-07 01:01:24

标签: python math numpy pandas

我在Stack Overflow找到了一些代码。但它不适用于浮点数。我试图找到5个局部最大和最小点加上极值。任何帮助将不胜感激。

from scipy.stats import gaussian_kde
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt

y=[ 191.78 ,   191.59,    191.59,    191.41,    191.47,    191.33,    191.25  \
  ,191.33 ,   191.48 ,   191.48,    191.51,    191.43,    191.42,    191.54    \
  ,191.5975,  191.555,   191.52 ,   191.25 ,   191.15  ,  191.01  ]
x = np.linspace(1 ,20,len(y))


fig, ax = plt.subplots(figsize=(10, 10))
ax.legend(loc='center left', bbox_to_anchor=(1.05, 0.5), frameon=False)
ax.scatter(x, y, color='black', label='data')
ax.plot(x,y,color='red')


sortId=np.argsort(x)
x=x[sortId]
y=y[sortId]

#this way the x-axis corresponds to the index of x
plt.plot(x-1,y)
plt.show()
maxm = argrelextrema(y, np.greater) 
minm = argrelextrema(y, np.less)

1 个答案:

答案 0 :(得分:0)

我做了更多研究,答案是使用正确的数组和numpy数组,如下所示:

PutStream
相关问题