带有时间表数据的烛台图显示了周末的空缺

时间:2019-02-01 14:42:56

标签: matlab matlab-figure candlestick-chart

首先,我认为找到的答案已经过时了:

  1. Excluding weekend gaps from financial timeseries plots
  2. Exclude Date Gaps in Time Series Plot in Matlab
  3. Datetick take into account NaN in plot

我的问题:
我已基于带有这些日期的时间表表创建了烛台图(格式为dd/mm/yyyy):

'25/01/2019'
'24/01/2019'
'23/01/2019'
'22/01/2019'
'21/01/2019'
'18/01/2019'
'17/01/2019'
'16/01/2019'
'15/01/2019'
'14/01/2019'
'11/01/2019'
'10/01/2019'
'09/01/2019'
'08/01/2019'
'07/01/2019'
'04/01/2019'
'03/01/2019'
'02/01/2019'
'28/12/2018'
'27/12/2018'
'26/12/2018'
'21/12/2018'
'20/12/2018'
'19/12/2018'
'18/12/2018'

这段代码:

candle(this.values);

这给了我这个情节:

values 1

如您所见,与非营业日相对应。

给出我对相同问题的答案:

  1. 创建了两个数组,一个带有日期,另一个带有日期字符串:

    this.dates = table2timetable(ticker(1:5:25,:));
    %sort them out because were generated in reverse order
    this.dates = timetable2table(sortrows(this.dates(:,1)));
    this.dates = this.aux(:,1);
    this.lbl = datestr(this.aux{:,1},'dd/mm/yyyy');
    
  2. 获取gca对象以设置X轴属性:

    this.ax = gca;
    this.ax.XTick = this.dates{:,1};
    this.ax.XTickMode = 'manual';
    this.ax.XTickLabel = this.lbl;
    

结果是这样的:

values 2

因此属性设置正确,但差距仍然存在。

最后,我尝试设置Timetable属性VariableContinuity并调用retime函数来生成包含NaN数据的缺少日期条目,以查看是否有帮助,但结果相同:

this.values.Properties.VariableContinuity = {'event','event','event','event','event','event','event','event'};
this.values = retime(this.values,'daily');

我还能做些什么来掩盖差距?

1 个答案:

答案 0 :(得分:0)

我相信,一旦绘制,就无法消除差距。在绘制之前,必须删除间隙。在时间表中,创建线性日期数组(无间隔),并将其用于时间表,然后进行绘图。这样,差距将不会存在,但日期将是错误的。把正确的日期,使用下面的代码(类似于你的代码)。

this.ax.XTickMode = 'manual';
this.ax.XTickLabel = YOUR_CORRECT_DATE_CELL_ARRAY