% -- External Function: cmap = spectral( nval ); % % Returns a RGB colormap/palette with `nval' values (default: nval=64) based on % the diverging palette `spectral' (10 levels) from http://colorbrewer2.org/ % Although there is a more-detailed (11 levels) version available on the % website, the odd-numbered versions have an excessively distinct central % level that breaks the `perceptual continuity' of the palette. You are % primarily using `spectral' as a sequential/qualitative palette (and not as % its original `diverging' purpose) and thus the continuity is paramount. % Copyright Cynthia Brewer, Mark Harrower and The Pennsylvania State University % Adapted for GNU Octave/Matlab by pst-laurent@vims.edu (2024-10-29). function cmap = spectral( nval ) if ( nargin < 1 ) nval = 64; end % Lookup table: The original palette had anywhere between 3-11 entries. % orig = [ 213 244 253 254 230 171 102 50; ... % 62 109 174 224 245 221 194 136; ... % 79 67 97 139 152 164 165 189 ]'; % 8 entries. orig = [ 158 213 244 253 254 230 171 102 50 94; ... 1 62 109 174 224 245 221 194 136 79; ... 66 79 67 97 139 152 164 165 189 162 ]'; % 10 entries. % orig = [ 158 213 244 253 254 255 230 171 102 50 94; ... % 1 62 109 174 224 255 245 221 194 136 79; ... % 66 79 67 97 139 191 152 164 165 189 162 ]'; % 11 entries. xori = (0 : size( orig, 1 ) - 1)' / (size( orig, 1 ) - 1); xitp = (0 : nval - 1)' / (nval - 1); cmap = interp1( xori, orig, xitp, 'pchip', 'extrap' ); clear orig xori xitp; cmap = cmap / 255.; % 0 <= RGB <= 255. cmap( find( cmap > 1. ) ) = 1.; cmap( find( cmap < 0. ) ) = 0.; % Reorder the palette to be cold-to-warm rather than original warm-to-cold. cmap = flip( cmap, 1 ); % Now in the same order as `jet'. end