I like to plot two groups of lines in the same plot. Each group has two lines with same color and I have to draw them in the order of one group after another group. I try to show legend for groups only not for lines. How can I do this? Here is a simplification of my wrong code:
plot(x1, y1, color1); hold on;
plot(x2, y2, color1); hold on;
plot(x3, y3, color2); hold on;
plot(x4, y4, color2); hold on;
legend({color1, color2})
Thanks!
UPDATE:
A new question, is there any way to write legend after each line and without overwriting the previous legend but append to it? i.e. something similar to “hold on” but applied to legend.
There are a few ways you can do this. The easiest way is to get the handle for the first plotted line of each group and pass that as the first argument to LEGEND: