How do I assign specific numbers (and letters) to the tick marks of a figure?

8 views (last 30 days)
Coming off of my previous question, I've successfully generated by chessboard...but now I need to change the axes (you know, to the standard letter and number labels).
Searching through the answers here yielded something like
e.g.
set(gca,'ytick',[1 8]);
Problem is, doing this causes all the values along the y-axis to disappear.
And of course, the x-axis would require letters...so how should I go about doing that?
Oh, and my board looks like this at the moment:
I suppose that means that even if I do successfully relabel them, the values along the y-axis will essentially be the wrong way around. How do I reverse the order of the values then?

Accepted Answer

Joshua
Joshua on 7 Nov 2014
Edited: Joshua on 8 Nov 2014
Okay, somehow managed to solve my problem thanks to both of you. Adam appears to be using an older version of MATLAB, but combined with Orion's solution it gave me the idea that led to me fixing my problem.
It's simply
xlab=zeros(rc,1);
for k=1:rc
xlab(k)=96+k;
end
set(gca,'XTickLabel',char(xlab))
After the image has already been displayed. rc is the number of rows (or columns, since it's a square board).
p.s. With just this, if the board is too big the tick labels will get all wonky. Something like
if rc>11
set(gca,'XTick',500*(1:rc))
end
might be required.

More Answers (2)

Orion
Orion on 29 Oct 2014
Hi,
you just probably need something like
Xtick = get(gca,'Xtick');
set(gca,'Xtick',linspace(Xtick(1),Xtick(end),8),'XtickLabel',('ABCDEFGH')')
Ytick = get(gca,'Ytick');
set(gca,'Ytick',linspace(Ytick(1),Ytick(end),8),'YtickLabel',num2str((8:-1:1)'))
you'll probably want to adjust the tick values for better positionning.

Adam
Adam on 29 Oct 2014
Edited: Adam on 7 Nov 2014
You can edit:
hAxes.XTickLabel
hAxes.YTickLabel
hAxes.YDir
for an axes hAxes. The yDir property can be either 'normal' or 'reverse', tick labels can be a cell array of whatever you want, but if make sure it is the same length as the number of ticks or else they will be either truncated or repeated in a cycle.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!