Discussion:
Making xticklabels position between ticks
(too old to reply)
James Smith
2005-04-21 10:42:32 UTC
Permalink
Hi all

I'm trying to customize my tick labels on a graph but am having
trouble positioning the xtick labels where I want them.

I'm plotting a frequency of objects that lie between certain ranges.
Thus I want tick marks on either side of the range displayed as eg.
10-20, as opposed to 10 at one tick mark and 20 at the next. so i
want
| 10-20 |
if possible.

I have this so far:
set(gca,'XTick',0:10:100,'tickdir','out')
set(gca,'XTickLabel',{'0-10','10-20','20-30','30-40','40-50','50-60','
60-70','70-80','80-90','90-100'})

This is almost right but I just need some way to centralise the
xticklabel as they appear directly beneath tickmarks at present.

Thanks in advance!

J. Smith
Jérôme
2005-04-21 11:19:38 UTC
Permalink
Hi,

one solution is to use a second transparent axes

ax1=axes('color','none','Ytick',[])
ax2=axes;
plot([0 95],[0 5])

set(gca,'XTick',0:10:100,'tickdir','out', ...
'XtickLabel',[])

set(ax1,'Xlim',get(ax2,'Xlim'),'XTick',5:10:100,...
'Xticklabel',{'0-10','10-20','20-30','30-40',...
'40-50','50-60','60-70','70-80',...
'80-90','90-100'})

Jérôme
Jérôme
2005-04-21 11:21:22 UTC
Permalink
oops

should read :

set(ax1,'Xlim',get(ax2,'Xlim'),'XTick',5:10:95,...

Same but cleaner ;)

Jérôme

Loading...