legend for transparent patch object is opaque ?
Mostrar comentarios más antiguos
Hello,
I create a simple figure with 2 patch objects where one of the patch is opaque and the other one is transparent (with facealpha set to 0.1) :
figure
x = [0 1 1 0];
y = [0 0 1 1];
patch(x,y,'red')
x2 = [3 6 6 3];
y2 = [3 3 6 6];
patch(x2,y2,'green','facealpha',0.1)
legend('red opaque -> OK','green is opaque instead of transparent -> WHY ?')
The legend does not reflect the fact that the green patch is transparent. I really need my legend to show if the patch is transparent or opaque. Is there a work around ?
Thanks !
Respuesta aceptada
Más respuestas (1)
Yun Guo
el 22 de Jun. de 2018
It is not very clear if you want green patch to be transparent, legend to be transparent, or both.
'facealpha' does work as expected. See example below.
- I changed the green patch's size so it overlaps with red patch to show transpareny works.
- I also removed legend box, so legend looks transparent.
figure
x = [0 1 1 0];
y = [0 0 1 1];
patch(x,y,'red');
x2 = [0.5 2 2 0.5];
y2 = [0.5 0.5 2 2];
patch(x2,y2,'green','facealpha',0.3)
l = legend('red opaque -> OK','green is opaque instead of transparent -> WHY ?');
set(l, 'Box', 'off')
5 comentarios
Matilda
el 22 de Jun. de 2018
Ameer Hamza
el 22 de Jun. de 2018
@Matilda, have you run the line
set(l, 'Box', 'off')
this is the expected output

Matilda
el 22 de Jun. de 2018
Ameer Hamza
el 22 de Jun. de 2018
I am trying on R2018a. Since you have R2017b, which I cannot try at the moment. But to correctly check the opacity move the legend over the red portion like this

Matilda
el 22 de Jun. de 2018
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

