Python find x value to corresponding max y value in plot

Viewed 59349

I've plotted a moving average from about 300,000 data points and I need to find the maximum y-value for the peak in the signal and its corresponding x-value, which would be its frequency. I'd like for it to give me the coordinates on the plot itself but if I can get it to at least print them out I'd be satisfied. Excuse my programming skills as they are not the strongest. Here's the section of the code I'm working on and a link to the plot that it generates. I don't have enough points to post the image.

def movingaverage(interval, window_size):
    window= np.ones(int(window_size))/float(window_size)
    return np.convolve(interval, window, 'same')

x = freq[0:300000]
y = fft
pylab.plot(x,y,"k.")
y_av = movingaverage(y, 30)
pylab.plot(x, y_av,"r")
pylab.xlim(0,10)
pylab.ylim(0,1500)
pylab.xlabel("Frequency")
pylab.ylabel("Moving Average Magnitude")
pylab.grid(True)
pylab.show() 

Moving Average Plot

1 Answers
Related