在Python的Matplotlib中,在2D-FFT图上绘制极坐标网格。

huangapple go评论122阅读模式
英文:

Plot polar grid above 2D-FFT plot in Python Matplotlib

问题

我已经使用numpy np.fft.fft2创建了一个2D FFT图,现在我想在这个2D FFT图上绘制一个极坐标网格,就像这个图像Plot and Plot with polar grid一样。

我尝试了类似以下的方法:

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

但我的输出是这样的:Output

有没有一种简单的方法在我的2D FFT结果中绘制极坐标网格?

随机数据:

  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3. a = np.mgrid[:10, :10][0]
  4. data=(np.abs(np.fft.fft2(a)))
  5. imgb=plt.imshow(np.abs(np.fft.fft2(data)))
  6. plt.show()
英文:

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:

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

But my output was this: Output

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

Random data

  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3. a = np.mgrid[:10, :10][0]
  4. data=(np.abs(np.fft.fft2(a)))
  5. imgb=plt.imshow(np.abs(np.fft.fft2(data)))
  6. plt.show()

答案1

得分: 0

根据这个回答,您可以在您的笛卡尔图上添加一个极坐标轴。

  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3. a = np.mgrid[:10, :10][0]
  4. data = (np.abs(np.fft.fft2(a)))
  5. fig, ax = plt.subplots()
  6. imgb = ax.imshow(np.abs(np.fft.fft2(data)))
  7. ax_polar = fig.add_axes(ax.get_position(), polar=True, frameon=False)
  8. ax_polar.set_yticklabels([])
  9. plt.show()

在Python的Matplotlib中,在2D-FFT图上绘制极坐标网格。

英文:

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

  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3. a = np.mgrid[:10, :10][0]
  4. data = (np.abs(np.fft.fft2(a)))
  5. fig, ax = plt.subplots()
  6. imgb = ax.imshow(np.abs(np.fft.fft2(data)))
  7. ax_polar = fig.add_axes(ax.get_position(), polar=True, frameon=False)
  8. ax_polar.set_yticklabels([])
  9. plt.show()

在Python的Matplotlib中,在2D-FFT图上绘制极坐标网格。

huangapple
  • 本文由 发表于 2023年7月17日 23:53:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706188.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定