Glasbey colormaps for categorical data#

Colorcet primarily includes continuous colormaps, where each color is meant to be equally spaced in perceptual color space from the preceding and following colors. The resulting colors then convey numerical magnitude to the viewer. Categorical data can also be represented as numbers, but each number is then distinct, with the numerical value important only to distinguish from other values. When categorical data is plotted as colors, each category should have a color visibly distinct from all the other colors, not nearby in color space, to make each category separately visible.

There are many sets of categorical colors available, but these tend to be relatively small numbers of hand-chosen colors, typically under 10 and nearly always under 25. To support visualizing larger numbers of categories, it would be good if an arbitrarily large number of colors could be chosen in a principled way from an available color space. Glasbey et al. presented such a method in:

Glasbey, Chris; van der Heijden, Gerie & Toh, Vivian F. K. et al. (2007), “Colour displays for categorical images”, Color Research & Application 32.4: 304-309.

Given a starting palette (e.g. white, black), this approach selects each new color to be maximally perceptually dissimilar from all the preceding colors, out of an allowed color space. Glasbey colors are available in ImageJ and for R, and there is a Python implementation of the method.

Generating the colors from Python is time consuming, so we have generated some specific large sets of Glasbey colors to distribute in colorcet, as outlined below. We’ll use Bokeh with HoloViews for displaying these colormaps so that you can zoom in for a closer look.

from colorcet.plotting import swatch, swatches, candy_buttons

import holoviews as hv