I'm having a bit of a problem with what's happening to the axes of 9 plots that get subplotted together. I'm using `subplot(3,3,x)` to make a 3x3 grid of 9 plots, and custom labeling the ticks of the axes with

``set(gca, 'XTickLabel', {'0,0','0,1','0,2','1,0','1,1','1,2','2,0','2,1','2,2'});set(gca, 'YTickLabel', {'0,0','0,1','0,2','1,0','1,1','1,2','2,0','2,1','2,2'});``

and the problem is that not all of the ticks specified show up on the subplots -- only about half of them, and they show up in the wrong places, at that.

I'm guessing this is matlab thinking that there isn't enough room to put all of the ticks and labels and showing a squeezed subset as a result, but it would look fine if it just did it. how do I make it all show up??

You can set the 'Xtick' & 'Ytick' property of the figure's axes. They define which ticks will be visible. In your case you want to show the first 9 xticks and the first 9 yticks - the following command will do it:

``````set(gca,'Xtick',1:9, 'Ytick',1:9)
``````

In case you want to show every 2nd tick you would use:

``````set(gca,'Xtick',1:2:9,'Ytick',1:2:9)
``````

Hope this helps.

You set custom tick labels with those commands, and they show up where the ticks are at that moment. You can see what the ticks are with

``````get(gca,'YTick');
``````

For example:

``````plot(-2:2)
get(gca,'YTick');
``````

returns `[-2 -1.5 -1 -0.5 0 0.5 1 1.5 2]`. If you now use

``````set(gca,'yticklabel',{'a','b','c','d','e'})
``````

then those letters will appear at all ticks, starting from the first (`-2`) and since there are more ticks than ticklabels, the ticklabels will repeat, as you can see:

So these are ticks, but maybe you meant to just use labels, which I add with the following:

``````ylabel('this is the ylabel');
xlabel('and this the xlabel');
``````

Play around with it and learn what's going, it's not that hard ;)

PS: with subplot, you can create different axes and set different ticks for each axes object separately. By default the axes are not linked or something, but completely independent! When you use `gca`, it returns the current axes, ie with subplot: the last one created or selected with `subplot(3,3,x)`!

So if you want to set ticks, labels are anything else on all the axes, you'll have to do it for all separately, ie:

``````subplot(3,3,1);
xlabel('x');
ylabel('y');
title('subplot (1,1)');
set(gca,'xticklabel',{'a','b','c'});
subplot(3,3,2);
xlabel('x');
ylabel('y');
title('subplot (1,2)');
subplot(3,3,1);
xlabel('x');
ylabel('y');
title('subplot (1,1)');
etc.
``````

It's a matter of space. Matlab will show more ticks if you increase the size of the plot window, and viceversa. You can also reduce the font size in order to fit more ticks on the axes (try with `set(gca,'FontSize',5)` or any other font size value).

Top