gpt4 book ai didi

matlab - x 轴和 y 轴刻度标签的不同字体大小

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:24 27 4
gpt4 key购买 nike

我想在 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)

最佳答案

您需要两个 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

关于matlab - x 轴和 y 轴刻度标签的不同字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38425342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com