Reset ColorOrder index for plotting in Matlab / Octave

前端 未结 5 1294
独厮守ぢ
独厮守ぢ 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:26

    If you want a slightly hacky, minimal lines-of-code approach perhaps you could plot an appropriate number of (0,0) dots at the end of each matrix plot to nudge your colourorder back to the beginning - it's like Mohsen Nosratinia's solution but less elegant...

    Assuming there are seven colours to cycle through like in matlab you could do something like this

    % number of colours in ColorOrder
    nco = 7;
    % plot matrix 1
    plot(x1');
    % work out how many empty plots are needed and plot them
    nep = nco - mod(size(x1,1), nco); plot(zeros(nep,nep));
    % plot matrix 2
    plot(x2');
    ...
    % cover up the coloured dots with a black one at the end
    plot(0,0,'k');
    

提交回复
热议问题