For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > Making xticklabels position between ticks









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Making xticklabels position between ticks
James Smith

2005-04-21, 9:00 am

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, 9:00 am

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, 9:00 am

oops

should read :

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

Same but cleaner ;)

Jérôme
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com