When working on the "Color Image Processing" chapter of DIPUM3E, I found myself often wanting to display square blocks (or swatches) of color, like this:
Eventually, I wrote a function, colorSwatches, to display a bunch of color squares using a single patch object. This function is used in DIPUM3E, and it is included in the MATLAB code files for the book. To call it, start with a set of RGB color values arranged in a Px3 matrix, where P is the number of colors. The lines functions returns the colors used by the MATLAB plot function:
c = lines(7) c = 0 0.4470 0.7410 0.8500 0.3250 0.0980 0.9290 0.6940 0.1250 0.4940 0.1840 0.5560 0.4660 0.6740 0.1880 0.3010 0.7450