How to use specific vector to define axis in imagesc?

18 views (last 30 days)
Hello Guys~
I used imagesc(x,y,v), then I want to do a reciprocal conversion of the y-axis, y=1/y. But the y-axis did not show the correct value.
So,the main problem here is how to use a definite vector whose value are corresponding to the image axis and has the same size with the image rows.
here are my code and results,
x=1:n;y=linspace(0,fmax,m)';
y=1./y; y=y(2:end);
figure('color',[1 1 1]);
imagesc(x,y,v);
you can change the parameter as you wish.
the total rows of v is 600, but the y-axis lable seems linear interpolate between 172.5 and 0, how to correctly lable the y-axis?Thank you very much!

Accepted Answer

Image Analyst
Image Analyst on 24 Sep 2021
You can change the tick marks manually. See xticks() and xticklabels().

More Answers (1)

Walter Roberson
Walter Roberson on 24 Sep 2021
Only the first and last XData and YData are paid attention to. That used to be documented explicitly; last time I looked the documentation implied that only scalar or vector length 2 is permitted.
  2 Comments
T0m07
T0m07 on 30 May 2023
You are right re the documentation, however imagesc also accepts vectors with lengths over 2 as inputs. I am confused about how to interpret MATLAB's use of these vectors. It would be useful to provide the x and y coordinates of each pixel in an image. Changing the tick labels is not as good - it's harder to overlay plots etc.
Do you know how I should interpret the longer vector inputs to imagesc?
Walter Roberson
Walter Roberson on 31 May 2023
imagesc() invokes image() internally. imshow() also invokes image() internally.
In image():
  • if XData or YData is not provided, then the image is placed so that the center of the bottom-left pixel is at data coordinate 1 in that dimension, and the center of the top-right pixel is at data coordinate equal to the size of the image in that dimension
  • if XData or YData is provided and is a scalar, then the image is placed so that the center of the bottom-left pixel is at the data coordinate provided by the user, and the center of the top-right pixel is at data coordinate that is size of the image in that dimension, minus 1, further on. For example, if 2 was the input and the image is 5 pixels in that dimension, the top-right center would be at 2+5-1 = 7 in that dimension
  • if XData or YData are provided and are a two-element vector, then the image is placed so that the center of the bottom-left pixel is at the first element of the vector in data coordinates, and the center of the top-right pixel as at the second element of the vector in the data coordinates
  • If XData or YData are provided and are more than two elements, then the first and last elements are the ones that are used. This used to be documented but does not appear in the documentation anymore.
Any elements of the XData or YData other than the first and last are ignored completely.
It is not possible to control the pixel-by-pixel placement of an image() object.
If you need to control the pixel-by-pixel placement, create a patch object defining faces and using patch() CData and related properties to define the color of each face. This allows you to control the exact boundaries of every pixel.
You might have possibly noticed pcolor around. pcolor() is internally surf() and view(2) . pcolor() does permit listing the locations of each X and Y. The challenge with pcolor() (and surf()) is that the color of each face is determined by interpolation between the four adjacent pixel data, rather than the pixel data giving color information directly. So if you had a red location immediately beside a blue location in the data, then pcolor() would create a purple pixel there. The number of pixels created in a direction is determined by the number of pairs of adjacent locations... and so is one fewer than the number of locations. If you had a data array that was 480 locations, then the image created would have 479 pixels in that direction. The X and Y coordinates are coordinates of vertices but the pixels are created by interpolating vertex colors.

Sign in to comment.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!