MATLAB: MATLAB plot: bring a line in front of an area

areaplot

Hello MATLAB users,
I am trying to plot two lines, on two different y axes, and one of them is filled below using the area function. My problem is that the filled area hides the other line, as well as the grid behind. How should I do to display the filled area at the back? I don't really like the transparency option since it "spoils" the color.
Any idea?
Thanks.
X =[1:1:100];
A = cos(X).*X/100;
B = sin(X).*X/100;
figure(2);
yyaxis right;
h = area(X,A,-100);
h.FaceColor = [1 1 0];
ylim([-1 1])
hold on
yyaxis left;
hh = plot(X,B,'b');
ylim([-1 1])
grid on;

Best Answer

One option is to reduce the 'FaceAlpha' of the area plot:
h.FaceAlpha = 0.5;
Related Question