find peak and bottom values from a series
Find every local peaks and bottom values
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
data = np.array([ 0.1, 1, 3, 1, 0.2, 1, 3.1, 3.2, 3, 1, 0 , -0.1, -0.2, -0.1, -0.2])
peak_index = signal.argrelextrema(data, np.greater_equal, order=1)
bottom_index = signal.argrelextrema(data, np.less_equal, order=1)
print('peak values are {}'.format(data[peak_index]))
print('bottom values are {}'.format(data[bottom_index]))
fig = plt.figure()
plt.plot(range(len(data)), data)
plt.scatter(peak_index, data[peak_index], color = 'red')
plt.scatter(bottom_index, data[bottom_index], color = 'blue')
plt.show()