matlabcolorsvisualizationlab-color-space

Plot Matlab colours as vertical bars


I stumbled upon this file exchange submission, which, given a positive integer, generates that many "maximally distinguishable" colours. The tool is working great, but I would like to visualize the colours it generates with coloured vertical bands. An example, taken from the linked blog article:

For the choice of colours:

ans =
         0         0    1.0000
    1.0000         0         0
         0    1.0000         0
         0         0    0.1724
    1.0000    0.1034    0.7241
    1.0000    0.8276         0
         0    0.3448         0

We obtain the vertical bands on the left that show these colours.


Solution

  • A fairly simple way would be as follows:

    a = [     0         0    1.0000 ;
         1.0000         0         0 ;
              0    1.0000         0 ;
              0         0    0.1724 ;
         1.0000    0.1034    0.7241 ;
         1.0000    0.8276         0 ;
              0    0.3448         0 ]
    
    figure
    imagesc(1:size(a, 1));
    colormap(a);
    % Optional, but neatens things up a bit
    set(gca, 'clim', [0.5 (size(a, 1) + 0.5)]);
    
    % Also optional, removes the ticks from the axes
    set(gca, 'xtick', [], 'ytick', []);
    

    output:

    enter image description here