2

In Matlab, suppose you imagesc a square matrix. Is there a way to plot the Xticklabels on the diagonal?

Pacific Stickler
  • 1,078
  • 8
  • 20
LeonaRdo
  • 124
  • 1
  • 9
  • 2
    I don't think there's an automated tool for that, but you can use the [`text`](http://www.mathworks.com/help/matlab/ref/text.html) command to achieve the same effect. – Eitan T Nov 09 '12 at 20:02
  • thanks a lot EitanT! It's a good hint! – LeonaRdo Nov 09 '12 at 20:17
  • No problem. If you're running into trouble, let me know -- I'll post an answer that shows how to do it. – Eitan T Nov 09 '12 at 20:23

1 Answers1

0

For a diagonal square matrix of size, n=4:

figure; imagesc( diag( ones(1, 4) )  );

Employ the text() command inside a loop to put the tick labels as strings:

for i = 1:n 
    text( i, i, num2str(i)); 
end

See below:

enter image description here

A good relevant reference: to Add labels on top of Histogram bars

Community
  • 1
  • 1
Pacific Stickler
  • 1,078
  • 8
  • 20