Why do not I see all the ticks being displayed in my plot when I use ‘XTickLabel’ in MATLAB 7.9 (R2009b)?

35 views (last 30 days)
When I try to add ticks to the x axis of the plot, I see that not all the ticks mentioned in the ‘XTickLabel’ appear in the plot.
For example if I run the following code, a plot is created with only 11 ticks displayed in x axis of the plot.
set(gca,'XTickLabel',{'JFM','FMA','MAM','AMJ','MJJ','JJA','JAS','ASO','SON','OND','NDJ','DJF','JFM','FMA','MAM'})

Answers (2)

Doug Hull
Doug Hull on 13 Jan 2011
There are two things which are relevant in this case XTICK and XTICKLABEL. Depending on how many XTICK you have on screen, than many XTICKLABELS will be displayed. So in order to display 15 XTICKLABELS, you need to have 15 XTICKS defined before using the XTickLabel for displaying ticks in the plot. Find the below sample code in relation to the same.
datay=randn(1,15);
datax=datay;
bar(datax,datay);
set(gca,'XTickLabel',{'JFM','FMA','MAM','AMJ','MJJ','JJA','JAS','ASO','SON','OND','NDJ','DJF','JFM','FMA','MAM'})
xTick=get(gca,'xtick');
xMax=max(xtick);
xMin=min(xtick);
newXTick=linspace(xMin,xMax,15);
set(gca,'xtick',1:15);

Walter Roberson
Walter Roberson on 13 May 2011
Only as many of the XTickLabel values will appear as there are values in XTick . Try
size(get(gca, 'XTick'))
to see how many XTick you have.

Categories

Find more on 2-D and 3-D Plots 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!