Reset ColorOrder index for plotting in Matlab / Octave

前端 未结 5 1289
独厮守ぢ
独厮守ぢ 2021-02-07 15:47

I have matrices x1, x2, ... containing variable number of row vectors. I do successive plots

figure
hold all % or hold on
plot(x1\'         


        
5条回答
  •  遥遥无期
    2021-02-07 16:31

    You can shift the original ColorOrder in current axes so that the new plot starts from the same color:

    h=plot(x1');
    set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h)))
    plot(x2');
    

    You can wrap it in a function:

    function h=plotc(X, varargin)
    h=plot(X, varargin{:});
    set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h)));
    if nargout==0,
        clear h
    end
    end
    

    and call

    hold all
    plotc(x1')
    plotc(x2')
    plotc(x3')
    

提交回复
热议问题