COLORDG - Provides a choice of 15 colors for a line plot The first seven colors are the same as Matlab's predefined values for the PLOT command, i.e. 'b','g','r','c','m','y','k' Syntax: linecolor = colordg(n); Input: N , integer between 1 and 15, giving the following colors 1 BLUE 2 GREEN (pale) 3 RED 4 CYAN 5 MAGENTA (pale) 6 YELLOW (pale) 7 BLACK 8 TURQUOISE 9 GREEN (dark) 10 YELLOW (dark) 11 ORANGE 12 MAGENTA (dark) 13 GREY 14 BROWN (pale) 15 BROWN (dark) Output: LINECOLOR (1 x 3 RGB vector) Examples: 1) h = line(x,y,'Color',colordg(11)); %Picks the orange color 2) colordg demo %Creates a figure displaying the 15 colors 3) axes; set(gca,'ColorOrder',(colordg(1:15))); Overrides the default ColorOrder for the current axes only 4) figure; set(gcf,'DefaultAxesColorOrder',(colordg(1:15))); Overrides the default ColorOrder for all axes of the current figure 5) set(0,'DefaultAxesColorOrder',(colordg(1:15))); Sets the default ColorOrder for all axes to be created during the current matlab session. You may wish to insert this command into your startup.m file. See also: PLOT, LINE, AXES
0001 function linecolor = colordg(n); 0002 %COLORDG - Provides a choice of 15 colors for a line plot 0003 %The first seven colors are the same as Matlab's predefined 0004 %values for the PLOT command, i.e. 0005 % 0006 % 'b','g','r','c','m','y','k' 0007 % 0008 %Syntax: linecolor = colordg(n); 0009 % 0010 %Input: N , integer between 1 and 15, giving the following colors 0011 % 0012 % 1 BLUE 0013 % 2 GREEN (pale) 0014 % 3 RED 0015 % 4 CYAN 0016 % 5 MAGENTA (pale) 0017 % 6 YELLOW (pale) 0018 % 7 BLACK 0019 % 8 TURQUOISE 0020 % 9 GREEN (dark) 0021 % 10 YELLOW (dark) 0022 % 11 ORANGE 0023 % 12 MAGENTA (dark) 0024 % 13 GREY 0025 % 14 BROWN (pale) 0026 % 15 BROWN (dark) 0027 % 0028 %Output: LINECOLOR (1 x 3 RGB vector) 0029 % 0030 %Examples: 0031 % 1) h = line(x,y,'Color',colordg(11)); %Picks the orange color 0032 % 2) colordg demo %Creates a figure displaying the 15 colors 0033 % 3) axes; set(gca,'ColorOrder',(colordg(1:15))); 0034 % Overrides the default ColorOrder for the current axes only 0035 % 4) figure; set(gcf,'DefaultAxesColorOrder',(colordg(1:15))); 0036 % Overrides the default ColorOrder for all axes of the current 0037 % figure 0038 % 5) set(0,'DefaultAxesColorOrder',(colordg(1:15))); 0039 % Sets the default ColorOrder for all axes to be created during 0040 % the current matlab session. You may wish to insert this 0041 % command into your startup.m file. 0042 % 0043 %See also: PLOT, LINE, AXES 0044 0045 %Author: Denis Gilbert, Ph.D., physical oceanography 0046 %Maurice Lamontagne Institute, Dept. of Fisheries and Oceans Canada 0047 %Web: http://www.qc.dfo-mpo.gc.ca/iml/ 0048 %August 2000; Last revision: 26-Sep-2003 0049 0050 if nargin == 0 0051 error('Must provide an input argument to COLORDG') 0052 end 0053 0054 colorOrder = ... 0055 [ 0 0 1 % 1 BLUE 0056 0 1 0 % 2 GREEN (pale) 0057 1 0 0 % 3 RED 0058 0 1 1 % 4 CYAN 0059 1 0 1 % 5 MAGENTA (pale) 0060 1 1 0 % 6 YELLOW (pale) 0061 0 0 0 % 7 BLACK 0062 0 0.75 0.75 % 8 TURQUOISE 0063 0 0.5 0 % 9 GREEN (dark) 0064 0.75 0.75 0 % 10 YELLOW (dark) 0065 1 0.50 0.25 % 11 ORANGE 0066 0.75 0 0.75 % 12 MAGENTA (dark) 0067 0.7 0.7 0.7 % 13 GREY 0068 0.8 0.7 0.6 % 14 BROWN (pale) 0069 0.6 0.5 0.4 ]; % 15 BROWN (dark) 0070 0071 if isnumeric(n) & n >= 1 & n <= 15 0072 linecolor = colorOrder(n,:); 0073 elseif strcmp(n,'demo') 0074 %GENERATE PLOT to display a sample of the line colors 0075 figure, axes; 0076 %PLOT N horizontal lines 0077 for n=1:length(colorOrder) 0078 h(n) = line([0 1],[n n],'Color',colorOrder(n,:)); 0079 end 0080 set(h,'LineWidth',5) 0081 set(gca,'YLim',[0 n+1],'YTick',[1:n],'XTick',[]) 0082 ylabel('Color Number'); 0083 else 0084 error('Invalid input to colordg'); 0085 end 0086