user3734366 user3734366 - 2 months ago 19
Python Question

Got an extra line on pyton plot

i'm using pyplot to show the FFT of the signal 'a', here the code:

myFFT=numpy.fft.fft(a)
x=numpy.arange(len(a))
fig2=plt.figure(2)
plt.plot(numpy.fft.fftfreq(x.shape[-1]),myFFT)
fig2.show()


and i get this figure
enter image description here

There is a line from the begin to the end of the signal in the frequency domain. How i can remove this line? i'm doing something wrong with pyplot?

Thank You

Answer

Have a look at plt.plot(numpy.fft.fftfreq(x.shape[-1]): the first and last points are the same, hence the graph "makes a loop"

You can do plt.plot(sorted(numpy.fft.fftfreq(x.shape[-1])),myFFT) or plt.plot(myFFT)