##### Getting proper x,y axis values
 Getting proper x,y axis values pyhill00 Silly Frenchman Posts: 20 Threads: 6 Joined: Mar 2019 Reputation: Jul-29-2022, 03:30 PM 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()``` Reply deanhystad Weighs the Same as a Duck Posts: 4,246 Threads: 16 Joined: Feb 2020 Reputation: 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()``` Reply pyhill00 Silly Frenchman Posts: 20 Threads: 6 Joined: Mar 2019 Reputation: 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()``` Reply deanhystad Weighs the Same as a Duck Posts: 4,246 Threads: 16 Joined: Feb 2020 Reputation: Jul-29-2022, 05:07 PM What do you mean "points"? Reply pyhill00 Silly Frenchman Posts: 20 Threads: 6 Joined: Mar 2019 Reputation: Jul-29-2022, 05:11 PM (Jul-29-2022, 05:07 PM)deanhystad Wrote: What do you mean "points"? My original post has points in the second plot. Reply deanhystad Weighs the Same as a Duck Posts: 4,246 Threads: 16 Joined: Feb 2020 Reputation: Jul-29-2022, 05:49 PM 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. Reply pyhill00 Silly Frenchman Posts: 20 Threads: 6 Joined: Mar 2019 Reputation: Jul-29-2022, 05:57 PM 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. Reply deanhystad Weighs the Same as a Duck Posts: 4,246 Threads: 16 Joined: Feb 2020 Reputation: 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. Reply pyhill00 Silly Frenchman Posts: 20 Threads: 6 Joined: Mar 2019 Reputation: Jul-29-2022, 06:48 PM 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 -_- Reply

 Possibly Related Threads… Thread Author Replies Views Last Post ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 1,968 May-17-2022, 11:38 AM Last Post: Larz60+ Proper way to do the OR statement? Mark17 5 930 Mar-01-2022, 01:54 PM Last Post: Mark17 Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 2,712 Sep-14-2021, 08:29 AM Last Post: hobbyist Put zero for x axis values quest 4 1,423 Jul-29-2021, 01:34 PM Last Post: DeaD_EyE Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 1,736 Aug-21-2020, 10:17 PM Last Post: JoeDainton123 proper use of 'end' in a 'with' statement ccrider27 1 1,419 Mar-18-2020, 10:33 PM Last Post: buran Proper use of if..elif..else statement nick1941 2 1,676 Mar-06-2020, 11:22 PM Last Post: nick1941 Proper Layout of Code Question TheJax 2 1,469 Feb-08-2020, 06:14 PM Last Post: TheJax Sort y axis by descening values matplotlib mrsenorchuck 0 3,110 Dec-08-2019, 08:13 PM Last Post: mrsenorchuck Unable to do the proper split using re.sub incase of missing data. Karz 1 1,333 Nov-17-2019, 05:58 PM Last Post: buran

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020