Matlab : put transparancy on a bar plot
Mostrar comentarios más antiguos
Hello, I have 2 different bar plot on a graph and I would like to put transparancy in order to see all the data even if my curves overlap. I try this code :
b1 = bar(x1,y1);%,'FaceColor',[0.2,0.2,0.5]);
set(get(b1,'Children'),'FaceAlpha',0.3)
hold on
b2 = bar(x1,y1,'FaceColor',[0,0.7,0.7]);
set(get(b2,'Children'),'FaceAlpha',0.2)
But it doesn't work. Also, I would like to calculate the probability of data which are in common between the 2 courb.
Thanks in advance,
Best regards
1 comentario
pfb
el 28 de Abr. de 2015
what do you exactly mean "it does not work"?
I'm asking because in my case it "sort of works". The bars do become transparent. Only, when they overlap, they produce a different color depending on which one is on top.
I see that you plot y1 vs x1 in both of your plots... But probably you re-define those between the two plots...
Respuesta aceptada
Más respuestas (2)
Juan Ignacio Bravo Pérez-Villar
el 18 de Mayo de 2016
Editada: Juan Ignacio Bravo Pérez-Villar
el 18 de Mayo de 2016
Hello, I found a simpler way to do it that works for me on Matlab 2015b
b1 = bar(x1,y1,'r');
b1.FaceAlpha = 0.5;
hold on
b2 = bar(x2,y2,'FaceColor',[0,0.7,0.7]);
b2.FaceAlpha = 0.5;
Hope its useful for somebody.
Regards,
1 comentario
Qin Liang
el 6 de Mzo. de 2017
Works properly and simple on Matlab 2016B
Chad Greene
el 3 de Mayo de 2015
This works find for me in 2012b:
x1 = [-5 -4 -1 3 4 5 6 7 10];
y1 = rand(size(x1));
b1 = bar(x1,y1);%,'FaceColor',[0.2,0.2,0.5]); %RXLEV
set(get(b1,'Children'),'FaceAlpha',0.3)
hold on
b2 = bar(x1,y1,'FaceColor',[0,0.7,0.7]);
set(get(b2,'Children'),'FaceAlpha',0.2)

If it's not properly transparent, try
set(gcf,'renderer','opengl')
1 comentario
Sarah Guiffray
el 5 de Mayo de 2015
Editada: Sarah Guiffray
el 5 de Mayo de 2015
Categorías
Más información sobre Annotations 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!

