MATLAB: How to plot a candle graph on top of an area graph when calling the CANDLE function before the AREA function

axesaxisMATLABplottopvisible

I would like to plot a candle graph on top of an area graph. However, I prefer to call the CANDLE function before I call the AREA function. When I do this, the area graph covers the candle graph completely. How do I ensure that the candle graph is seen as well?

Best Answer

The following code demonstrates an example of plotting a candle graph on top of an area graph when calling the CANDLE function before the AREA function:
close all;
%%Plot candle on a2 axes
a2 = axes;
High = [5 7 6 4]';
Low = [2 3 2 1]';
Close = [3 4 3 2]';
Open = [4 3 6 3]';
candle(High, Low, Close, Open);
%%Plot area on a1 axes
a1 = axes;
x = linspace(0, 4, 100);
y = 8*rand(1, 100);
area(x, y);
%%Make sure a2 is on top
set(gcf, 'Children', [a2; a1])
%%Make second axes invisible
set(a2, 'Visible', 'off');
%%Link the axes limits
linkaxes([a1 a2], 'xy');
%%Adjust the limits
ylim([0 10]);