How do I assign specific numbers (and letters) to the tick marks of a figure?
Show older comments
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
More Answers (2)
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.
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 Creating, Deleting, and Querying Graphics Objects 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!