Divide a series of data under another

When you plot in Matlab, the most recent series of data built is placed on top of everything you already have. For example:

figure; hold on plot(sin(linspace(0,pi)),'linewidth',4,'color',[0 0 1]) plot(cos(linspace(0,pi)),'linewidth',4,'color',[1 0 0]) 

Here the red line is displayed on top of the blue line (where they intersect). Is there a way to set the β€œhow deep” the line is so that you can build plots below what is already there?

+7
matlab plot
source share
2 answers

Use the uistack command. For example:

 h1 = plot(1:10, 'b'); hold on; h2 = plot(1:10, 'r'); 

will build two lines with a red line built on top of the blue line. If you do this:

 uistack(h1); 

the blue line will be brought to the fore.

+20
source share

You can also accomplish this by setting the order of the children vector of the current axes. If you do the following:

 figure; hold on h1 = plot(sin(linspace(0,pi)),'linewidth',4,'color',[0 0 1]); h2 = plot(cos(linspace(0,pi)),'linewidth',4,'color',[1 0 0]); h = get(gca, 'Children'); 

you will see that h is a vector containing h1 and h2. The graphical stacking order is represented by the handle order in h. In this example, to reverse the stacking order you could do:

 h = flipud(h); set(gca, 'Children', h); 
+4
source share

All Articles