2

我有从 0 到 96 的 x 轴,其中每个数字代表一天中的一刻钟(96/4 = 24 小时)。我需要轴来显示小时 0 到 24 没有办法在绘图后只修改轴吗?

4

2 回答 2

1

有几种方法。一个好的方法可能是更改绘图的 x 数据:

%# get handles of plot objects
chH = get(gca,'children');
%# for each child: divide the x-data by 4 and put it back
if length(chH) == 1
   set(chH,'xdata',get(chH,'xdata')/4);
else
   set(chH,{'xdata'},cellfun(@(x)x/4,get(chH,'xdata'),'uni',0));
end
xlim([0 24])

这会读取绘制到当前坐标区中的对象的 x 数据,将其除以 4,然后放回原处。然后将轴范围更改为 0...24

于 2013-05-11T18:31:31.773 回答
1

您可以使用:

>> set(gca, 'XTick', 0:4:96);
>> set(gca, 'XTickLabel', 0:24);

例如:

>> plot(0:96,0:96)
>> set(gca, 'XTick', 0:4:96);
>> set(gca, 'XTickLabel', 0:24);

结果图:

在此处输入图像描述

于 2013-05-11T18:58:03.003 回答