Posts: 20
Threads: 6
Joined: Mar 2019
I am trying to change the values of the axes so that the x and y values (0.3,0.4) and (0.3,1) are shown on the axes for the points. Anyone know how to properly do this? from scipy.fft import fft2, fftshift
import numpy as np
import matplotlib.pyplot as plt
from skimage.filters import window
from scipy.fftpack import fftfreq
k = np.linspace(0,4.76*10,2400)
kx,ky = np.meshgrid(k, k)
x1 = 0.3
y1 = 0.4
x2 = 0.3
y2 = 1
z = 0.05*np.cos(2*np.pi*kx*x1 + 2*np.pi*ky*y1) + 0.05*np.cos(2*np.pi*kx*x2 + 2*np.pi*ky*y2)
wz = z * window('hann', z.shape)
plt.figure(0)
plt.imshow(wz)
f = fftfreq(len(k), np.diff(k)[0])
zf = np.abs(fftshift(fft2(wz)))[1200:, 1200:]
plt.figure(1)
plt.axis([0,100, 0,100])
plt.imshow(zf)
plt.show()
Posts: 6,779
Threads: 20
Joined: Feb 2020
Jul-29-2022, 04:05 PM
(This post was last modified: Jul-29-2022, 04:05 PM by deanhystad.)
Why? Normally axis labels indicate range with maybe some subdivisions to give approximate value. If you want the real value you click on the plot.
You can tell matplotlib where to put tickmarks like this:
import numpy as np
import matplotlib.pyplot as plt
from math import sin
x = np.linspace(0.0, np.pi * 2, 100)
x1 = 1
y1 = sin(1)
x2 = 5
y2 = sin(5)
fig, ax = plt.subplots()
plt.plot(x, np.sin(x))
ax.set_xticks((x1, x2))
ax.set_yticks((y1, y2))
ax.grid(True)
plt.show()
Posts: 20
Threads: 6
Joined: Mar 2019
Jul-29-2022, 04:43 PM
(This post was last modified: Jul-29-2022, 04:44 PM by pyhill00.)
(Jul-29-2022, 04:05 PM)deanhystad Wrote: Why? Normally axis labels indicate range with maybe some subdivisions to give approximate value. If you want the real value you click on the plot.
It seems I got the axes right but now the points are not showing up. Do you know whats wrong with my code here?
from scipy.fft import fft2, fftshift
import numpy as np
import matplotlib.pyplot as plt
from skimage.filters import window
from scipy.fftpack import fftfreq
k = np.linspace(0,4.76*10,2400)
kx,ky = np.meshgrid(k, k)
x1 = 0.3
y1 = 0.4
x2 = 0.3
y2 = 1
z = 0.05*np.cos(2*np.pi*kx*x1 + 2*np.pi*ky*y1) + 0.05*np.cos(2*np.pi*kx*x2 + 2*np.pi*ky*y2)
wz = z * window('hann', z.shape)
plt.figure(0)
plt.imshow(wz)
f = fftfreq(len(k), np.diff(k)[0])
zf = np.abs(fftshift(fft2(wz)))[1200:, 1200:]
fig, ax = plt.subplots()
ax.set(xlim=(0, 2), ylim=(0, 2))
ax.imshow(zf,extent=[0,f[:k.size//2][-1], 0 , f[:k.size//2][-1]])
plt.show()
Posts: 6,779
Threads: 20
Joined: Feb 2020
What do you mean "points"?
Posts: 20
Threads: 6
Joined: Mar 2019
(Jul-29-2022, 05:07 PM)deanhystad Wrote: What do you mean "points"?
My original post has points in the second plot.
Posts: 6,779
Threads: 20
Joined: Feb 2020
Both times you are drawing an image. That is what imshow() does. The image may be generated from data, but you are still plotting an image. I don't know why you would want to plot points that way since it removes all the point information.
Posts: 20
Threads: 6
Joined: Mar 2019
The goal of imshow is to show the frequencies...not sure what you are trying to get it. It's pretty obvious I want to see where the frequency plots are of an fft.
Posts: 6,779
Threads: 20
Joined: Feb 2020
Jul-29-2022, 06:46 PM
(This post was last modified: Jul-29-2022, 06:46 PM by deanhystad.)
So when you say you cannot see the "points" does that mean that you cannot see the FFT frequency plot at all? Be aware that I cannot run your example, so all I know about the visibility of "points" is what you have posted.
Posts: 20
Threads: 6
Joined: Mar 2019
I got it: ax.imshow(zf, origin='lower', extent=[0,f[:k.size//2][-1], 0 , f[:k.size//2][-1]])
origin was not on the bottem left -_-
|