title: How do I plot an fft in python using scipy and modify the frequency range so that it shows the two peaks frequencies in the center?
body: <p>The following Python code uses numpy to produce a frequency plot of a sinusoid graph :</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import scipy.fftpack
  
  # Number of samplepoints
  N = 600
  # sample spacing
  T = 1.0 / 800.0
  x = np.linspace(0.0, N*T, N)
  y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
  yf = scipy.fftpack.fft(y)
  xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
  
  fig, ax = plt.subplots()
  ax.plot(xf, 2.0/N * np.abs(yf[:N//2]))
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ZMYmA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZMYmA.png" alt="enter image description here" /></a></p>
  <p>Based on the code above , we are plotting a sine wave with two frequencies, one at 50Hz and another at 80 Hz. You can clearly see the Fourier transform plot shows peaks at those two frequencies.</p>
  <p>My question: How do I modify the above code so that the x-axis ranges from 0-100Hz ?</p>
  <p>If I change</p>
  <pre><code>xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
  </code></pre>
  <p>to</p>
  <pre><code>xf = np.linspace(0.0, 100, N//2)
  </code></pre>
  <p>Then my graph looks like:</p>
  <p><a href="https://i.stack.imgur.com/jqWHv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jqWHv.png" alt="enter image description here" /></a></p>
  <p>But the graph now shows my peaks at around 11 and 20Hz, which is not correct.  When I change my axis, the peak values should not change.</p>
  <p>What am I doing wrong?</p>