12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- function map = tab10(N)
- % Qualitative colormap from MatPlotLib, for plots using the line ColorOrder.
- % In MatPlotLib 2 it is named VEGA10, for MatPlotLib 3 was renamed TAB10.
- %
- % Copyright (c) 2017-2019 Stephen Cobeldick
- %
- %%% Syntax:
- % map = tab10
- % map = tab10(N)
- %
- % For MatPlotLib 2.0 improved colormaps were created for plot lines of
- % categorical data. The new colormaps are introduced here:
- % <http://matplotlib.org/2.0.0rc2/users/dflt_style_changes.html>
- % VEGA10/TAB10 is the default Line Color Order for MatPlotLib 2 and 3.
- %
- % MATLAB axes ColorOrder (note that this is NOT the axes COLORMAP):
- % <https://www.mathworks.com/help/matlab/creating_plots/defining-the-color-of-lines-for-plotting.html>
- % <https://www.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html>
- %
- %% Examples %%
- %
- %%% PLOT using matrices:
- % N = 10;
- % axes('ColorOrder',tab10(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 = 10;
- % set(0,'DefaultAxesColorOrder',tab10(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 = 10;
- % set(0,'DefaultAxesColorOrder',tab10(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 TAB20 TAB20B TAB20C SET VIRIDIS TWILIGHT 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 = ['#1f77b4';'#ff7f0e';'#2ca02c';'#d62728';'#9467bd';'#8c564b';'#e377c2';'#7f7f7f';'#bcbd22';'#17becf'];
- raw = sscanf(hex.','#%2x%2x%2x',[3,Inf]).';
- %
- map = raw(1+mod(0:N-1,size(raw,1)),:) / 255;
- %
- end
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%tab10
|