MATLAB: How to display a plot and area on the same axes

area plot axes

I have two data sets of the same size. I want to make them appear on the same x axes with different y axes. The problem is they overwrite each other.
area( data1 );
set(gca, 'YAxisLocation','Right');
set(gca, 'YLim', [0 8]);
plot( data2 );
Any help is appreciated. Thanks in advance.

Best Answer

Use plotyy() if they must have different y axes. If they can share the y axis, then before the second plot() call, add
hold on
(You might want to also add a color specification on the plot() call)
Related Question