x轴和y轴的刻度标签的不同字体

时间:2016-07-17 19:51:18

标签: matlab plot matlab-figure

我想在x轴和y轴上有不同字体大小的刻度标签。

我的第一次尝试是:

set(gca,'XTickLabel', {labelslist}, 'FontSize',16)

但它不起作用,至少在我的版本上(Windows10上的2014a)。由于某种原因,它会更改两个轴上的标签字体大小。

有谁知道怎么做?

最小例子:

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)

1 个答案:

答案 0 :(得分:2)

您需要两个axes个对象,一个用于 x ,另一个用于 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)

enter image description here

关于你的评论,不要混淆句柄:

%// 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)

enter image description here

相关问题