Filter löschen
Filter löschen

How to draw a rectangle over a patch?

18 Ansichten (letzte 30 Tage)
Nathaniel Levi Blank
Nathaniel Levi Blank am 21 Apr. 2021
Bearbeitet: giannit am 7 Mai 2021
Hello, I need to draw a rectangle with curved edges over a background that I created using patch(). For the rectangle I am using the function rectangel() because it has a curvature property. I know that other functions have a property like 'layer' that lets me place things on top of others, but rectangle() doesn't have this property. I am open to alternative methods of creating the rounded rectangle or the background so that I can get the final result.
Thanks in advance!

Akzeptierte Antwort

Jan
Jan am 21 Apr. 2021
Bearbeitet: Jan am 21 Apr. 2021
You can draw into different AXES objects, while the top one is invisible:
FigH = figure;
Axes1H = axes(FigH, 'XLim', [0, 100], 'YLim', [0, 100]);
Axes2H = axes(FigH, 'XLim', [0, 100], 'YLim', [0, 100], ...
'Visible', 'off'); % On top of Axes1H
patch(Axes1H, [20, 20, 80, 80], [10, 90, 90, 10], [1,0,0])
rectangle(Axes2H, 'Position', [10, 40, 80, 30], 'Curvature', 0.5)
  2 Kommentare
Nathaniel Levi Blank
Nathaniel Levi Blank am 22 Apr. 2021
Great, thanks!
giannit
giannit am 7 Mai 2021
Bearbeitet: giannit am 7 Mai 2021
You can decide who stays at top simply using the Z-axis coordinates of patch.
This will plot the same as Jan
Z = 0*ones(1,4);
patch([20, 20, 80, 80], [10, 90, 90, 10], Z, [1,0,0])
rectangle('Position', [10, 40, 80, 30], 'Curvature', 0.5)
while with Z = 1*ones(1,4) it will plot the patch over the rectangle.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by