Which line is on top in a matlab graph?

20 views (last 30 days)
I am trying to make a simple plot with four sets of data, using different line properties for each data set. For some reason, Matlab seems to plot the lightest colored line on top of the darker lines, and I need to be able to see all of the darkest line, with the lighter lines in the background. Is there any way I can set which line is on top in the plot? Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 15 Jun 2011
For renderers other than OpenGL, the last object drawn should be the one on top, but you can change that order by using uistack()
For OpenGL, lines that are drawn in the same plane do not necessarily have a defined rendering order; the work-around for OpenGL is to use a 3D line and use larger Z values for the lines you want to be on top.

More Answers (2)

Paulo Silva
Paulo Silva on 15 Jun 2011
It's the order of the plots, last thing to be added to the axes stays on top, see this example:
clf
hold on
x=0:0.1:10;
plot(x,sin(x),'linewidth',10)
plot(x,cos(x),'r','linewidth',10)
ch=get(gca,'children')
pause(2) %after two seconds the blue line goes to the top
set(gca,'children',[ch(2) ch(1)]) %reorder the children of the axes

Fangjun Jiang
Fangjun Jiang on 15 Jun 2011
I don't think it is the lightness or darkness of the color. It is the order of the plot that matters. Reverse the order of the following code to see the effect.
plot(2:-1:1,'g','linewidth',10);
hold
plot(1:2,'r','linewidth',10);

Tags

Community Treasure Hunt

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

Start Hunting!