Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Axis labeling in imagesc

Subject: Axis labeling in imagesc

From: Susan

Date: 17 Mar, 2013 07:00:25

Message: 1 of 4

I am using imagesc to plot a 10x10 matrix, but I want the xaxis labels to say 0:9, not the indicies 1:10. And I want the yaxis labels to flip and go 9:0. I have tried using XTick and YTick to change them, but it doesn't shift the values it just doesn't label 10. Also YTick returns an error "Error using set. Values must be monotonically increasing"

colormap('gray')
Xtick = [0 1 2 3 4 5 6 7 8 9];
Ytick = [9 8 7 6 5 4 3 2 1 0];
imagesc(matrix)
set(gca,'XTick',Xtick)
set(gca,'YTick',Ytick)

Subject: Axis labeling in imagesc

From: Image Analyst

Date: 17 Mar, 2013 19:03:19

Message: 2 of 4

Susan:
Use xticklabel instead of xtick:

matrix = magic(10);
colormap('gray')
imagesc(matrix)
set(gca,'YTickLabel',{'9' '8' '7' '6' '5' '4' '3' '2' '1' '0'})
set(gca,'XTickLabel',{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})

Subject: Axis labeling in imagesc

From: Bruno Luong

Date: 17 Mar, 2013 19:13:10

Message: 3 of 4

"Susan" wrote in message <ki3pm9$cdf$1@newscl01ah.mathworks.com>...
> I am using imagesc to plot a 10x10 matrix, but I want the xaxis labels to say 0:9, not the indicies 1:10. And I want the yaxis labels to flip and go 9:0. I have tried using XTick and YTick to change them, but it doesn't shift the values it just doesn't label 10. Also YTick returns an error "Error using set. Values must be monotonically increasing"
>

% Normal plot
subplot(1,2,1); imagesc(peaks(10));

% Customized axis plot
subplot(1,2,2); imagesc([0 9],[0 9],flipud(peaks(10))); set(gca,'YDir','normal')

% Bruno

Subject: Axis labeling in imagesc

From: Susan

Date: 17 Mar, 2013 21:11:10

Message: 4 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ki54k6$54d$1@newscl01ah.mathworks.com>...
> "Susan" wrote in message <ki3pm9$cdf$1@newscl01ah.mathworks.com>...
> > I am using imagesc to plot a 10x10 matrix, but I want the xaxis labels to say 0:9, not the indicies 1:10. And I want the yaxis labels to flip and go 9:0. I have tried using XTick and YTick to change them, but it doesn't shift the values it just doesn't label 10. Also YTick returns an error "Error using set. Values must be monotonically increasing"
> >
>
> % Normal plot
> subplot(1,2,1); imagesc(peaks(10));
>
> % Customized axis plot
> subplot(1,2,2); imagesc([0 9],[0 9],flipud(peaks(10))); set(gca,'YDir','normal')
>
> % Bruno

Thank you! This solved my problem.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us