在子图中更改 XTick 不起作用
Change XTick in subplot not working
我有很多子图必须使用 Matlab 加载并放在一起。我想添加个性化 Ticks,但我的方法似乎不起作用。我的 mwe 如下:
x = 1:1:1000;
r = rand(1000,1);
my1 = subplot(2,3,1);
my1 = bar(x,sort(r));
title ('This works')
xlabel ('This works too')
xlim ([0 1000])
my = get(gca);
my.XTick = [1 200 499]
最后一点是行不通的。为什么?我该如何解决?
get(gca)
returns 当前轴的所有图形属性的 struct
,而不是轴句柄本身。对此 struct
属性所做的任何更改都不会反映在您的实际 axes
中。您需要直接使用 set
修改 axes
的属性
set(gca, 'XTick', [1 200 499])
或者如果您在 2014b
% Don't use get(gca) to get the handle
ax = gca;
% Set the XTick property
ax.XTick = [1 200 499];
我有很多子图必须使用 Matlab 加载并放在一起。我想添加个性化 Ticks,但我的方法似乎不起作用。我的 mwe 如下:
x = 1:1:1000;
r = rand(1000,1);
my1 = subplot(2,3,1);
my1 = bar(x,sort(r));
title ('This works')
xlabel ('This works too')
xlim ([0 1000])
my = get(gca);
my.XTick = [1 200 499]
最后一点是行不通的。为什么?我该如何解决?
get(gca)
returns 当前轴的所有图形属性的 struct
,而不是轴句柄本身。对此 struct
属性所做的任何更改都不会反映在您的实际 axes
中。您需要直接使用 set
axes
的属性
set(gca, 'XTick', [1 200 499])
或者如果您在 2014b
% Don't use get(gca) to get the handle
ax = gca;
% Set the XTick property
ax.XTick = [1 200 499];