How to bring a patch to the bottom of a figure?

15 views (last 30 days)
How to bring a patch to the bottom of a figure?
(Maybe with uistack?)
[EDITED] In the following figure, I would like to have the two lines at the top, while the patch at the very bottom of the figure.
hold on
a = plot([1 2 3],[1 2 3],'color','k','LineWidth',3);
b = plot([4 3 2],1:3,'color','r','LineWidth',3);
c = fill([0 4 5 2 1],[0 0 2 4 3],'y');
hold off
  3 Comments
Sim
Sim on 6 Mar 2023
Edited: Sim on 6 Mar 2023
yes, sorry, I edited it... now it is in this way, and I would like to see the two lines at the very top, i.e. with the patch as background...
hold on
a = plot([1 2 3],[1 2 3],'color','k','LineWidth',3);
b = plot([4 3 2],1:3,'color','r','LineWidth',3);
c = fill([0 4 5 2 1],[0 0 2 4 3],'y');
hold off
Sim
Sim on 6 Mar 2023
oh gosh, it was very simple... sorry for this silly question..
hold on
a = plot([1 2 3],[1 2 3],'color','k','LineWidth',3);
b = plot([4 3 2],1:3,'color','r','LineWidth',3);
c = fill([0 4 5 2 1],[0 0 2 4 3],'y');
hold off
uistack(c,'bottom')

Sign in to comment.

Accepted Answer

Voss
Voss on 6 Mar 2023
Option 1: Call fill before plot:
figure()
hold on
c = fill([0 4 5 2 1],[0 0 2 4 3],'y');
a = plot([1 2 3],[1 2 3],'color','k','LineWidth',3);
b = plot([4 3 2],1:3,'color','r','LineWidth',3);
hold off
Option 2: Use uistack(_,'bottom'):
figure()
hold on
a = plot([1 2 3],[1 2 3],'color','k','LineWidth',3);
b = plot([4 3 2],1:3,'color','r','LineWidth',3);
c = fill([0 4 5 2 1],[0 0 2 4 3],'y');
hold off
uistack(c,'bottom')

More Answers (1)

Les Beckham
Les Beckham on 6 Mar 2023
The code you originally posted already had the lines on top.
Just plot the lines after the patch.
hold on
c = fill([0 4 5 2 1],[0 0 2 4 3],'y');
a = plot([1 2 3],[1 2 3],'color','k','LineWidth',3);
b = plot([4 3 2],1:3,'color','r','LineWidth',3);
hold off

Categories

Find more on Interactive Control and Callbacks 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!