MATLAB: Independent XTickLabel and YTickLabel font sizes

fontsizeMATLABplot

Is it possible to set the font size of y-tick marks independently of the font size of the x-tick marks, ylabel and xlabel?
When I use:
set(gca,'YTick',[-pi 0 pi], 'YTickLabel', {'-\pi','0','\pi'}, 'fontsize', 18);
it sets the fonts size for all labels to the same size. Is there a standard MATLAB function to do this?

Best Answer

The documentation includes examples that use the numeric rulers (introduced in release R2015b) that are part of the axes to do this type of customization. You can also change the properties of the objects stored in the XLabel and YLabel properties of the axes.
% Sample data
x = -1:0.01:1;
y = 3*asin(x);
% Plot it and retrieve the handles of the objects we're going to manipulate
h = plot(x, y);
yL = ylabel('Abracadabra');
xL = xlabel('For demonstration purposes only', 'Color', 'r');
ax = ancestor(h, 'axes');
yrule = ax.YAxis;
% Change properties of the axes
ax.YTick = [-pi 0 pi];
ax.YTickLabel = {'-\pi','0','\pi'};
% Change properties of the ruler
yrule.FontSize = 18;
% Change properties of the label
yL.FontSize = 8;
Some of the manipulation I did (in particular changing the YTick and YTickLabel properties of the axes) I could have done via several of the objects as well. But in order to change the font size of the X and Y axes independently I need the ruler. Changing the axes FontSize using ax would change all of the X tick labels, X label, Y tick labels, and Y label.