Changing layers on a bar graph

I am making a plot like this:
I want to move the green rectangles behind the two bars. Is there any ways to achieve that other than simply chanign the transparency?
Thanks for everyone who answers my question!

 Respuesta aceptada

Adam Danz
Adam Danz el 1 de Ag. de 2022
Editada: Adam Danz el 1 de Ag. de 2022

0 votos

Plot the green bars first, before the bar plot.
Alternatively use uistack to control the stacking order of graphics objects.

5 comentarios

Jiaqi Wang
Jiaqi Wang el 1 de Ag. de 2022
Thank you for the anwser! I have the code like this:
p = bar(x, vGRF)
p.FaceColor = 'flat';
p.CData(1,:) = r;
p.CData(2,:) = y;
rec1 = rectangle('Position',[0.55, 0.45, 0.9, 0.1],'FaceColor', 'g')
rec2 = rectangle('Position',[1.55, 0.45, 0.9, 0.1],'FaceColor', 'g')
uistack([p])
It seems that uistack only moves the red bar on top of the green box. Is there anyway to access both bars and put them above the boxes?
Plot the green bars first.
rec1 = rectangle('Position',[0.55, 0.45, 0.9, 0.1],'FaceColor', 'g')
hold on
rec2 = rectangle('Position',[1.55, 0.45, 0.9, 0.1],'FaceColor', 'g')
p = bar(x, vGRF)
p.FaceColor = 'flat';
p.CData(1,:) = r;
p.CData(2,:) = y;
Jiaqi Wang
Jiaqi Wang el 2 de Ag. de 2022
I tried the method above. The problem was that this step was built in a for loop to plot real-time bar plot. Everytime it runs, the bars were overlayed as well. I tried hold off, which did not solve this problem.
I really appreciate your answer!
Adam Danz
Adam Danz el 2 de Ag. de 2022
Editada: Adam Danz el 4 de Ag. de 2022
Demo:
figure
bar(1:3)
hold on
h = plot([0,4],[.5 .5],'k-','LineWidth', 5);
figure
bar(1:3)
hold on
h = plot([0,4],[.5 .5],'k-','LineWidth', 5);
uistack(h,'bottom')
Jiaqi Wang
Jiaqi Wang el 4 de Ag. de 2022
This works perfectly! Thank you so much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Centro de ayuda y File Exchange.

Preguntada:

el 1 de Ag. de 2022

Comentada:

el 4 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by