Reputation: 13
BytesReceived = df.iloc[:,0].values
print(type(BytesReceived)) #1d array
print(currentThreshold)
peaks = find_peaks(BytesReceived, height = currentThreshold)[0]
plt.plot(BytesReceived)
plt.plot(peaks, BytesReceived[peaks],"X")
plt.show()
I am using find_peaks to find peaks in my graph (above code)
But after displaying peaks in graph, I also wanted to print output on the basis of presence of peak. Like, if peak is present do this and if not do this.
Initially, I was thinking, if I can count number of peaks and put the condition on that basis.
I will be grateful, if anyone can help regarding this.
Upvotes: 0
Views: 156
Reputation: 799
It is not 100% clear to me what you are aiming at. I assume, you would like to add a marker X at all positions that are above a given threshold.
import matplotlib.pyplot as plt
import pandas as pd
BytesReceiver = pd.DataFrame( random.sample(range(0, 100), 50), columns=['Data'])
threshold = 70
peaks = BytesReceiver[BytesReceiver.Data > threshold]
plt.plot(BytesReceiver)
plt.scatter(peaks.index, peaks.Data, c='r', marker='X') #marker: red cross
plt.show()
Count the peaks
There are several options, for instance: Check the existence of any peak and do something.
if (peaks.any(axis=None)):
print("Has peaks")
else:
print("Has no peaks")
Use the amount of peaks to do something.
if (len(peaks) > 0):
print("Has peaks")
else:
print("Has no peaks")
Upvotes: 1