How to create a transparent, rectangular patch with rounded corners?
365 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Chris L'Esperance
am 16 Jan. 2019
Kommentiert: jon erickson
am 15 Mai 2024
It would be helpful to create a transparent, rectangular patch with rounded corners. This could be acheived with something like this:
h = rectangle('Position', [x1, y1, x2, y2], ...
'Curvature', 0.2, ...
'FaceColor', 'r', ...
'EdgeColor', 'r');
Unfortunately, rectangle properties do not include FaceAlpha and EdgeAlpha. Patch objects do, so I thought that I could get the XData and YData properties of the rectangle object from which to create a patch object. No dice; wasn't able to find these properties.
Again, the desired features are: transparency + rounded corners + face color
0 Kommentare
Akzeptierte Antwort
Afiq Azaibi
am 26 Apr. 2024
Verschoben: Adam Danz
am 8 Mai 2024
bar(magic(4));
r = rectangle(Position=[1.5,0,1,12],FaceColor='r',FaceAlpha=.3,Curvature=[.4 .4]);
0 Kommentare
Weitere Antworten (5)
Jon
am 18 Sep. 2019
You can use the rectangle function if you give the color as a triple instead of a string and add a fourth argument which specifices the alpha. Here, the alpha is 0.7.
h = rectangle('Position', [x1, y1, x2, y2], ...
'Curvature', 0.2, ...
'FaceColor', [1, 0, 0, 0.7], ...
'EdgeColor', [1, 0, 0, 0.7]);
3 Kommentare
jon erickson
am 15 Mai 2024
4th color argument -brilliant solution for those of us with older versions. Thank you!
Jan
am 16 Jan. 2019
Bearbeitet: Jan
am 16 Jan. 2019
A rectangle object does not have XData and YData properties and it does not allow to set the transparency by Alpha blending. This means clearly, that you cannot use rectangle to solve your problem, although it looks almost like you want it.
All you need is to define the XData and YData according to your inputs. The equations for the rounded corners can be obtained by some simple equations. I'm not sure, how the "Curvature" of rectangle objects is defined. It should be easy to find the required circles, but it is a tedius work.
H W
am 5 Jun. 2023
IN YOU FIGURE, you select the input rectange, open Attribute checker, set the facealpha. ok!
1 Kommentar
Walter Roberson
am 5 Jun. 2023
rectangle() objects do not have a FaceAlpha property; https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.rectangle-properties.html
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!