function map = tab20b(N) % Qualitative colormap from MatPlotLib, for plots using the line ColorOrder. % In MatPlotLib 2 it is named VEGA20b, for MatPlotLib 3 was renamed TAB20b. % % Copyright (c) 2017-2019 Stephen Cobeldick % %%% Syntax: % map = tab20b % map = tab20b(N) % % For MatPlotLib 2.0 improved colormaps were created for plot lines of % categorical data. The new colormaps are introduced here: % % VEGA10/TAB10 is the default Line Color Order for MatPlotLib 2 and 3. % % MATLAB axes ColorOrder (note that this is NOT the axes COLORMAP): % % % %% Examples %% % %%% PLOT using matrices: % N = 20; % axes('ColorOrder',tab20b(N),'NextPlot','replacechildren') % X = linspace(0,pi*3,1000); % Y = bsxfun(@(x,n)sqrt(n)*sin(x+2*n*pi/N), X(:), 1:N); % plot(X,Y, 'linewidth',4) % %%% PLOT in a loop: % N = 20; % set(0,'DefaultAxesColorOrder',tab20b(N)) % X = linspace(0,pi*3,1000); % Y = bsxfun(@(x,n)sqrt(n)*sin(x+2*n*pi/N), X(:), 1:N); % for n = 1:N % plot(X(:),Y(:,n), 'linewidth',4); % hold all % end % %%% LINE using matrices: % N = 20; % set(0,'DefaultAxesColorOrder',tab20b(N)) % X = linspace(0,pi*3,1000); % Y = bsxfun(@(x,n)sqrt(n)*cos(x+2*n*pi/N), X(:), 1:N); % line(X(:),Y) % %% Input and Output Arguments %% % %%% Inputs (*=default): % N = NumericScalar, N>=0, an integer to define the colormap length. % = *[], use the length of the current figure's colormap (see COLORMAP). % %%% Outputs: % map = NumericMatrix, size Nx3, a colormap of RGB values between 0 and 1. % % See also TAB10 TAB20 TAB20C SET TWILIGHT VIRIDIS LINES COLORMAP PARULA if nargin<1 N = size(get(gcf,'colormap'),1); else assert(isscalar(N)&&isreal(N),'First argument must be a real numeric scalar.') assert(fix(N)==N&&N>=0,'First argument must be a positive integer.') end % hex = ['#393b79';'#5254a3';'#6b6ecf';'#9c9ede';'#637939';'#8ca252';'#b5cf6b';'#cedb9c';'#8c6d31';'#bd9e39';'#e7ba52';'#e7cb94';'#843c39';'#ad494a';'#d6616b';'#e7969c';'#7b4173';'#a55194';'#ce6dbd';'#de9ed6']; raw = sscanf(hex.','#%2x%2x%2x',[3,Inf]).'; % map = raw(1+mod(0:N-1,size(raw,1)),:) / 255; % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%tab20b