How to plot multiple lines with different markers

后端 未结 6 1673
感情败类
感情败类 2021-02-03 12:27

I would like to plot multiple lines with MATLAB and do it so, that markers would be different in every line. I know that with colours this would be achieved with ColorSet

6条回答
  •  遇见更好的自我
    2021-02-03 13:04

    Yes, there's a ready made method: it's the LineStyleOrder axis property. To activate it you have to disable the ColorOrder property, which takes precedence over the former and is activated by default. You can do as follows:

    m = {'+','o','*','.','x','s','d','^','v','>','<','p','h'};
    set_marker_order = @() set(gca(), ...
        'LineStyleOrder',m, 'ColorOrder',[0 0 0], ...
        'NextPlot','replacechildren');
    

    where the m values were obtained manually from the output of help plot. Then use it as in this example:

    x = linspace(0, 2*pi);
    y = cos(bsxfun(@plus, x(1:15:end), x'));
    figure
    set_marker_order()
    plot(x, y)
    

提交回复
热议问题