Hi, I'm wanting to make a standard financial plot with a candestick chart on top, and candle volume bar plot underneath, with both axes linked. Both axes have the same datetime arrays on the x-axes. The result is the following:
A problem arises however when axes are linked, with this error msg:
Error using linkaxes>syncLimits (line 172)linkaxes requires the limits of all the axes be all numeric, all datetime or all duration values.Error in linkaxes (line 100) syncLimits(ax,'XLim');
I'm not sure why this error is occurring, given that both x-axes are created using the same datetime array.
The code I'm using:
dat = csvread('candle_data.csv', 1, 0); hlco = dat(:,[3,4,5,2]); % reorder columns to High, Low, Close, Open
dates = datetime( dat(:,1), 'ConvertFrom', 'posixtime'); % get dates from unix timestamps
figure;% plot candles
ax1 = subplot(2,1,1);axes(ax1);candle(hlco(:,1), hlco(:,2), hlco(:,3), hlco(:,4), 'b', dates, 'dd-mmm'); % plot candle volumes
ax2 = subplot(2,1,2);bar(dates, dat(:,6)) %link
linkaxes([ax1, ax2], "x")
A possible explanation for the error is that there is a mismatch in the representations used for the x-axis between candle and bar plots. Curiously, xlim for the candle plot is shown as [737134 737137], while for the bar plot as
1×2 datetime array Mar 15, 2018, 00:00 Mar 17, 2018, 12:00
Any suggestions as to how these axes can be linked while still showing datetime's along the x-axes would be appreciated.
Thanks
Josh
Best Answer