How to set front and back lines on plot with yyaxis left and right
Show older comments
Hi,
I have a situation where I would like the plot of the right axis (yyaxis right) to be "under" the plot from the left axis (yyaxis left). Here is a simplified code sample:
x = 1:0.001:100;
y = sin(x);
y2 = awgn(y,2); % Add noise
figure(1)
yyaxis right
p2 = plot(x,y2);
yyaxis left
p1 = plot(x,y);
legend([p2,p1],'Curve that should be behind','curve that should be in front')
The problem (I think) is that the left axis is called first no matter what. So even if I specify the right axis first, the left curve will still be under the one on the right. I am not able to change this using children of the figure (specify the right axis to be plotted first instead of left).
In my application, I would really like to keep the curve on their side, because it would be uniform with other figure in my article. What happens is that the curve on the right is noisier than the one on the left, which is why I would like to have it under in this format (using yyaxis).
Thanks in advance for any ideas you could have!
1 Comment
Adam Danz
on 2 Mar 2022
I'll add your thread to the list....
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


