Reputation: 2351
I would like to have tick labels with different font size on x- and y-axis.
My first try was:
set(gca,'XTickLabel', {labelslist}, 'FontSize',16)
but it does not work, at least on with my version (2014a on Windows10). For some reason it changes the label font size on both axis.
Does anyone know how to do it?
minimal example:
A=[1 2 3; 2 3 4; 2 3 4; 1 1 1];
figure
bar([1:size(A,1)], A, 'BarWidth', 2)
set(gca,'xticklabel',{'1','2','3','4'},'FontSize',16)
Upvotes: 4
Views: 2802
Reputation: 25232
You need two axes
objects on top of each other, one for x and one for y:
%// example figure
A = [1 2 3; 2 3 4; 2 3 4; 1 1 1];
figure
bar([1:size(A,1)], A, 'BarWidth', 1)
%// handle
ax1 = gca;
%// fontsize of y-axis, deactivate, x-axis
set(ax1,'XTick',[],'FontSize',24)
%// create second identical axis and link it to first one
ax2 = axes('Position', get(ax1, 'Position'),'Color','none');
linkaxes([ax1,ax2],'xy')
%// fontsize of x-axis, deactivate, y-axis
set(ax2,'YTick',[],'FontSize',12)
Regarding your comment, don't mix up the handles:
%// handle
ax1 = gca;
%// fontsize of y-axis, deactivate, x-axis
set(ax1,'XTick',[],'YTick',0:4,'YTickLabel',{'ZERO','ONE','TWO','THREE','FOUR'},'FontSize',24)
%// create second identical axis and link it to first one
ax2 = axes('Position', get(ax1, 'Position'),'Color','none');
linkaxes([ax1,ax2],'xy')
%// fontsize of x-axis, deactivate, y-axis
set(ax2,'YTick',[],'XTick',1:4,'XTickLabel',{'one','two','three','four'},'FontSize',12)
Upvotes: 2