Tickmarks not showing up on imagesc figure?

I used imagesc on an array to visualize it... my issue now is with setting the tick marks on the axes. I want there to be only two tick marks on the x and y axis each with -1 and 1 so I do xticks([-1 1]) and yticks([-1 1]) but on the figure the only thing that shows up are the y ticks and those ticks are 1 at the bottom and 1 at the top, which should be -1 at the bottom and 1 at the top, and then the same for the x axis... any help?

Answers (1)

Use the 'XData' and 'YData' options:
rgbImage = imread('peppers.png');
imagesc(rgbImage, 'XData', [-1,1], 'YData', [-1,1]);
axis on
xticks([-1, 1]);
yticks([-1, 1]);

2 Comments

hmm still not working. I have a 100x100 array that I'm inputting into imagesc to create the figure, and when I plot it raw the x and y axis go to 200. I want to rescale it just so that the first tick is -1 and the last and second tick is 1 for both x and y... but as I said it's only showing the y axis ticks when I do this and they only go from 1 to 1.
Here's proof it works:
rgbImage = imread('peppers.png');
rgbImage = imresize(rgbImage, [100,100]); % Make it 100x100
imagesc(rgbImage, 'XData', [-1,1], 'YData', [-1,1]);
axis on
xticks([-1, 1]);
yticks([-1, 1]);
Please post your code with proof that it doesn't work.

Sign in to comment.

Tags

Asked:

on 14 Mar 2018

Commented:

on 14 Mar 2018

Community Treasure Hunt

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

Start Hunting!