0
votes

First of all, I think the answers I've found are outdated:

  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

My problem:
I've created a candlestick graph based on a Timetable table with these dates (the format is 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'

And this code:

candle(this.values);

This gives me this plot:

values 1

As you can see, there are gaps corresponding to the non-business days.

Given the answers that I've found to the same problem what I did was:

  1. Created two arrays one with the dates and the other with dates strings:

    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. Obtain the gca object to set the X-axis properties:

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

And the result is this:

values 2

So the properties are being set correctly but the gaps remain.

Finally I've tried to set the Timetable property VariableContinuity and called the retime function to generate the missing dates entries with NaN data to see if that helped but with the same results:

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

What else could I do to hide the gaps?

1
It's unclear how you want to hide the gaps and maintain a continuous scale? Or do you not care that the time-based x-axis will not be linear in time when you remove gaps? From a data visualisation perspective, I'd rather see the gaps than have a date axis which doesn't show a continuous date! If you're desperate, you could convert the dates to categoricals, then they wouldn't be dates and MATLAB would just treat them as categories not a continuous scale. - Wolfie
@Wolfie it's not a continuous scale, this are stock prices. Every stock chart that I've ever seen (and I've seen plenty) only shows business days. I'd rather not see the gaps. I'm not desperate. Still, do you realize that in the posts that I've mentioned there used to be a solution that aparently doesn't work anymore? I think there should be a workaround or some kind of property that help me to get this done. - Typo
@Wolfie also, when you do Technical Analysis it helps a lot not having this gaps. - Typo

1 Answers

0
votes

I believe that once plotted, you cannot remove the gaps. You have to remove the gaps before plotting. In your timetable, create a linear date array (no gaps) and use this for the timetable, then plot. Then, the gaps will not be there but the dates will be wrong. To put the right date, use the following code (similar to your code).

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