MATLAB: set line's color and style order to be applied in parallel

后端 未结 2 526
清酒与你
清酒与你 2021-01-02 20:12

When you set DefaultAxesColorOrder and DefaultAxesLineStyleOrder MATLAB will first cycle through all colors with the first style, then again throug

2条回答
  •  迷失自我
    2021-01-02 20:41

    Amro's approach works well. Just as a note, you don't have to set the defaults to do this. You can do something like this

    col = mycolors(); % defines RGB colors scaled to [0,1]
    
    i = 1;
    c(:,i) = col.royal_blue; i = i+1;
    c(:,i) = col.crimson; i = i+1;
    c(:,i) = col.medium_sea_green; i = i+1;
    c(:,i) = col.coral; i = i+1;
    c(:,i) = col.dark_magenta; i = i+1;
    
    colord = num2cell(c',2);
    lineord = {'-' '--' '-.'}'; 
    
    set(h,{'Color'}, colord(rem((1:numel(h))-1,numel(colord))+1), ...
          {'LineStyle'}, lineord(rem((1:numel(h))-1,numel(lineord))+1))
    set(h,'LineWidth',2)
    

    Edit: the mycolors() function is home made. I define

    colors.maroon = [128,0,0];
    colors.dark_red = [139,0,0];
    colors.brown = [165,42,42];
    ...
    

    (the color names are from this http://www.rapidtables.com/web/color/RGB_Color.htm). Then I scale them to [0,1] via

    c = fieldnames(colors);
    for i = 1:numel(c)
        colors.(c{i}) = colors.(c{i})/255;
    end
    

提交回复
热议问题