八度音程中 datetick 的意外行为

Unexpected behavior of datetick in octave

以下代码应显示从 startDate=datenum('2016-01-01');endDate=datenum('2016-12-31'); 的数据:

data=[ 7.3633e+05,     3460.4;
  7.3635e+05,     3119.7;
   7.364e+05,     2777.9;
  7.3642e+05,     2202.6;
  7.3649e+05,     569.57;
  7.3656e+05,      403.1;
  7.3658e+05,      789.5;
  7.3664e+05,     2242.1;
  7.3668e+05,     3120.6 ]

startDate=datenum('2016-01-01');
endDate=datenum('2016-12-31');

xData = linspace(startDate,endDate,12)
plot(data(:,1),data(:,2));

ax = gca;
set (ax, 'xtick',xData);
datetick (29, 'x');

但是 datetick 似乎忽略了 xData 中的值,如下图所示。在我看来,它应该显示 2016-01-01 到 2016-12-31 范围内的日期。

问题是您切换了 datetick 的前两个输入。如您所写,Octave 将读取第一个输入 29,并将其用作格式(如您所料);但是,格式规范之后的任何尾随输入都用于indicate the start date to use (rather than relying on the tick values themselves). This seems to be intentionally undocumented behavior

datestr(double('x'), 29)
%   0000-04-29

为了获得预期的行为,you need to flip the order of the two inputs 作为轴规范('x')应该放在第一位。

datetick('x', 29)

此外,如果您想准确指定 xticks 的位置,您需要使用 "keepticks" 选项。

datetick('x', 29, 'keepticks')