0

I have created a 2D FFT plot using numpy np.fft.fft2 and now I would like to plot a polar grid in this 2D FFT like this image Plot and Plot with polar grid.

I have tried something like:

import numpy as np
from matplotlib import pyplot as plt
ax = plt.subplot(1, 1, 1, projection='polar')
ax.set_theta_direction(-1)
ax.set_theta_offset(np.pi / 2.0)
ax.imshow(brightvv, extent=[makexax[0], makexax[-1], makeyax[0], makeyax[-1]])
plt.show()

But my output was this: Output

Is there easy way to plot the polar grid in my 2D-fft result?

Random data

import numpy as np
from matplotlib import pyplot as plt
a = np.mgrid[:10, :10][0]
data=(np.abs(np.fft.fft2(a)))
imgb=plt.imshow(np.abs(np.fft.fft2(data)))
plt.show()
kolrocket
  • 9
  • 3
  • In what way do you want to map the points from cartesian to polar? – jared Jul 17 '23 at 15:56
  • Hi! This is my first time working with polar coordinates so I am not sure which one is the best... If you have any tips I'd appreciate that. Thanks you! – kolrocket Jul 18 '23 at 12:03
  • I just need to add the circles in the 2dfft plot, while maintaining the axis given by the 2dfft (if thats possible). – kolrocket Jul 18 '23 at 12:11
  • There is no "best" option. I can't tell you what would be the right way to map what you have. Is the center of your current plot that center of the polar plot and you just want to clip off the corners or is each row a different radius and each column mapped to a different theta value? – jared Jul 18 '23 at 13:06
  • Sorry, I'm a little confused. Based on this https://i.stack.imgur.com/MZMH5.png (please note that the images are different FFTs, I only put the second to show the grid I need), the corners are not clipped. The center of the plot is the origin shifted. So I guess its the second option you mentioned? – kolrocket Jul 18 '23 at 13:57

1 Answers1

0

Following this answer, you can add a polar axis on top of your cartesian plot.

import numpy as np
from matplotlib import pyplot as plt

a = np.mgrid[:10, :10][0]
data = (np.abs(np.fft.fft2(a)))

fig, ax = plt.subplots()
imgb = ax.imshow(np.abs(np.fft.fft2(data)))
ax_polar = fig.add_axes(ax.get_position(), polar=True, frameon=False)
ax_polar.set_yticklabels([])
plt.show()

jared
  • 4,165
  • 1
  • 8
  • 31