Which line is on top in a matlab graph?
Show older comments
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
More Answers (2)
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
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);
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!