Skip to content

fix: mark glasbey as qualitative - #142

Open
matthiasschabel wants to merge 1 commit into
pyapp-kit:mainfrom
matthiasschabel:fix-glasbey-categorical
Open

fix: mark glasbey as qualitative#142
matthiasschabel wants to merge 1 commit into
pyapp-kit:mainfrom
matthiasschabel:fix-glasbey-categorical

Conversation

@matthiasschabel

@matthiasschabel matthiasschabel commented Aug 7, 2026

Copy link
Copy Markdown

glasbey is recorded as a continuous miscellaneous colormap, but it is a categorical palette: 256 maximally distinct colors for labelling categories, ordered so that any prefix stays distinguishable (Glasbey et al., doi:10.1002/col.20327 — "Colour displays for categorical images").

Two consequences today:

>>> from cmap import Colormap
>>> cm = Colormap("glasbey")
>>> cm.category, cm.interpolation
('miscellaneous', 'linear')      # blends between unrelated categories
>>> len(cm.lut(1000))
1000                             # from a palette that defines 256

Evidence, using only colormaps this catalog labels — median distance between adjacent entries:

import numpy as np
from cmap import Colormap

def step(name):
    cm = Colormap(name)
    lut = np.asarray(cm.lut(cm.num_colors), float)[:, :3]
    return float(np.median(np.linalg.norm(np.diff(lut, axis=0), axis=1)))
median adjacent step
glasbey 0.698
catalog's qualitative colormaps 0.524 (range 0.163–1.077)
matplotlib:viridis 0.006
cmocean:thermal 0.007

Change

src/cmap/data/glasbey/record.json: categoryqualitative, interpolationfalse, matching how tol's discrete palettes are recorded.

After: category == "qualitative", interpolation == "nearest", and num_colors == 256 is respected.

One test added in tests/test_glasbey.py.

Glasbey's palette is 256 maximally distinct colors for labelling categories
(Glasbey et al., doi:10.1002/col.20327), but is recorded as a continuous
`miscellaneous` colormap. Consequences: it is interpolated between colors that
denote unrelated categories, and `Colormap("glasbey").lut(1000)` returns 1000
colors rather than the 256 that exist.

Measured, the median CIE Lab step between adjacent entries is 75.7 — within the
19.3–116.6 range spanned by the catalog's own qualitative colormaps, and nowhere
near its continuous ones (0.9 for matplotlib:viridis).
@matthiasschabel
matthiasschabel marked this pull request as ready for review August 7, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant