title: Fourier Transform in Python 2D
body: <p>I want to perform numerically <code>Fourier transform</code> of <code>Gaussian function</code> using <code>fft2</code>. Under this transformation the function is preserved up to a constant.</p>
  
  <p>I create 2 grids: one for <code>real space</code>, the second for <code>frequency</code> (momentum, k, etc.). (Frequencies are shifted to zero). I evaluate functions and eventually plot the results.</p>
  
  <p>Here is my code</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.fftpack import fft2, ifft2
  from mpl_toolkits.mplot3d import Axes3D
  
  """CREATING REAL AND MOMENTUM SPACES GRIDS"""
  N_x, N_y = 2 ** 11, 2 ** 11
  range_x, range_y = np.arange(N_x), np.arange(N_y)
  dx, dy = 0.005, 0.005
  # real space grid vectors
  xv, yv = dx * (range_x - 0.5 * N_x), dy * (range_y - 0.5 * N_y)
  dk_x, dk_y = np.pi / np.max(xv), np.pi / np.max(yv)
  # momentum space grid vectors, shifted to center for zero frequency
  k_xv, k_yv = dk_x * np.append(range_x[:N_x//2], -range_x[N_x//2:0:-1]), \
              dk_y * np.append(range_y[:N_y//2], -range_y[N_y//2:0:-1])
  
  # create real and momentum spaces grids
  x, y = np.meshgrid(xv, yv, sparse=False, indexing='ij')
  kx, ky = np.meshgrid(k_xv, k_yv, sparse=False, indexing='ij')
  
  """FUNCTION"""
  f = np.exp(-0.5 * (x ** 2 + y ** 2))
  F = fft2(f)
  f2 = ifft2(F)
  """PLOTTING"""
  fig = plt.figure()
  ax = Axes3D(fig)
  surf = ax.plot_surface(x, y, np.abs(f), cmap='viridis')
  # for other plots I changed to
  # surf = ax.plot_surface(kx, ky, np.abs(F), cmap='viridis')
  # surf = ax.plot_surface(x, y, np.abs(f2), cmap='viridis')
  plt.show()
  </code></pre>
  
  <p>So, the plots for <code>gaussian, fourier(gaussian), inverse_fourier(fourier(gaussian))</code> are the following:<a href="https://i.stack.imgur.com/VNFJf.png" rel="nofollow noreferrer">Initial</a>, <a href="https://i.stack.imgur.com/cihSu.png" rel="nofollow noreferrer">Fourier</a>, <a href="https://i.stack.imgur.com/HGXxg.png" rel="nofollow noreferrer">Inverse Fourier</a></p>
  
  <p>Using <code>plt.imshow()</code>, I additionally plot fourier of gaussian:</p>
  
  <pre><code>   plt.imshow(F)
     plt.colorbar()
     plt.show()
  </code></pre>
  
  <p>The result is as follows: <a href="https://i.stack.imgur.com/NXEE9.png" rel="nofollow noreferrer">imshow</a></p>
  
  <p>That doesn't make sense. I expect see the same <code>gaussian function</code> as the initial up to some constant order of unity.</p>
  
  <p>I would be very glad if someone could clarify this for me.</p>