Plotting a line above / below existing lines created using a storyline

I run this code:

t = linspace(0, 10, 1000); y1 = 2*t; y2 = 3*t; figure; [ax, h1, h2] = plotyy(t, y1, t, y2); set(h1, 'LineWidth', 4); set(h2, 'LineWidth', 4); hold on; h3 = plot([5, 5], [0, 3000], 'LineWidth', 6, 'Color', [0.6, 0.6, 0.6]); 

What creates this plot:

enter image description here

Notice how the vertical gray line appears above the blue line (y1), but below the green line (y2).

How to build a gray line on top of two other lines or below two other lines?

+4
source share
2 answers

I see two options:

a. Move the gray line forward by moving it to the second axes created by the plotyy team

 set(h3,'parent',ax(2)); 

B. Place the gray line at the bottom, rearranging the blue and gray lines on the axis.

 chld = [h1 h3]; set(ax(1),'children',chld); %# reorders the two lines so that the gray line is in back. 
+3
source

To make the bottom gray line, you can also change the drawing order.

 t = linspace(0, 10, 1000); y1 = 2*t; y2 = 3*t; figure; h3 = plot([5, 5], [0, max(y1)], 'LineWidth', 6, 'Color', [0.6, 0.6, 0.6]); hold on; [ax, h1, h2] = plotyy(t, y1, t, y2); set(h1, 'LineWidth', 4); set(h2, 'LineWidth', 4); 

There is a trick in h3 = plot(...) to make sure that the left scale is correct.

enter image description here

+2
source

Source: https://habr.com/ru/post/1401048/


All Articles