- place twice as many tickmarks as you need, and then make every second string empty. This would approximate what you requested, and be quite simple code.
- Place exactly the tickmarks that you want, and make the tickmarklabels empty. The use text to place the labels in the positions that you want to:
How to make special ticks with user defined text labels?
1 view (last 30 days)
Show older comments
I would like to use equally distributed ticks on the x-axes, but I would like to determine the number of ticks, and also its labels. More precisely it would be nice to put the text labels between ticks and not below the ticks. Is it possible?
0 Comments
Accepted Answer
Stephen23
on 11 Mar 2015
Edited: Stephen23
on 11 Mar 2015
You should read the axes properties documentation , which lists everything that you can customize in axes. In particular you should look at the keys related to tickmarks : XTick and XTickLabel will both be needed to make custom locations and labels.
At the top of that page the documentation also explain how to use the keys, either using set or the new dot notation.
As far as I am aware you cannot place tickmarklabels between the tickmarks. As an alternative you could:
A = rand(1,11);
plot(0:10,A)
set(gca,'XTick',0:2.5:10, 'XTickLabels',[])
yval = get(gca,'Ylim');
xpos = 1.25:2.5:10;
text(xpos,yval(1)*ones(size(xpos)),{'Hello','World','Test','Labels'},...
'VerticalAlignment','top','HorizontalAlignment','center')
You might also like to read the section on the key TickLabelInterpreter, as this causes many beginners surprises when they have underscore characters _ or other special characters in their text.
2 Comments
Stephen23
on 11 Mar 2015
Edited: Stephen23
on 11 Mar 2015
Although you know what "this not works" means, we do not. Unless you write what "this not works" actually means in terms of your plot and what you see on your computer, I will assume that the command caused your computer to catch fire. You should call the fire brigade.
More Answers (0)
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!