how to plot the FFT of a list of values

Thomas Jollans tjol at tjol.eu
Mon Dec 7 09:46:47 EST 2020


On 05/12/2020 23:08, Christian Gollwitzer wrote:
> Am 05.12.20 um 18:16 schrieb Boris Dorestand:
>> I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ...  I
>> compute its fourier transform using
>>>>>>> from scipy import fft, ifft
>>>>> x = [1,2,4,8,1,2,4,8]
>>>>> fft(x)
>> array([ 30. +0.j,   0. +0.j,  -6.+12.j,   0. +0.j, -10. +0.j, 0. +0.j,
>>          -6.-12.j,   0. +0.j])
>>>> Now how can I plot these values?  I would like to plot 16 values.  What
>> do I need to do here?  Can you show an example?
>>> Usually, for the FFT of real input data, you plot only the magnitude 
> or square of the complex array, and usually on a logscale. So:
>> import pylab

Don't use pylab.
https://matplotlib.org/api/index.html#module-pylab
Use matplotlib.pyplot directly instead. "plt" is a popular shorthand:
from matplotlib import pyplot as plt
#...
plt.semilogy(...) # or plt.plot, etc.
- Thomas
> import numpy as np
>> fx = fft(x)
>> pylab.semilogy(np.abs(fx))
> pylab.show()
>>>>     Christian
>>>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /