英文:
Plot polar grid above 2D-FFT plot in Python Matplotlib
问题
我已经使用numpy np.fft.fft2
创建了一个2D FFT图,现在我想在这个2D FFT图上绘制一个极坐标网格,就像这个图像Plot and Plot with polar grid一样。
我尝试了类似以下的方法:
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()
但我的输出是这样的:Output
有没有一种简单的方法在我的2D FFT结果中绘制极坐标网格?
随机数据:
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()
英文:
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()
答案1
得分: 0
根据这个回答,您可以在您的笛卡尔图上添加一个极坐标轴。
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()
英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论