legend for group of lines

后端 未结 6 440
盖世英雄少女心
盖世英雄少女心 2020-12-08 07:46

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

6条回答
  •  半阙折子戏
    2020-12-08 08:38

    You can stitch multiple lines together using NaN, which means "pick up the pen". Then the legend will treat each as a single set of data.

    hold on
    plot([x1 NaN x2], [y1 NaN y2], 'b');
    plot([x3 NaN x4], [y3 NaN y4], 'r');
    legend({'foo', 'bar'})
    hold off
    

    For convenience, you can stick this in the multi-line version of plot.

    plot([x1 NaN x2], [y1 NaN y2], 'b', [x3 NaN x4], [y3 NaN y4], 'r');
    

    This could let you set() properties for the grouped lines as units, too.

提交回复
热议问题