Skip to content

MNT: Avoid colour map name collisions, as newer matplotlib does not like us overriding built-ins.

Paul McCarthy requested to merge paulmc/fsleyes:mnt/matplotlib into master

FSLeyes has a handful of colour maps with names that clash with built-in matplotlib colour maps. Early on during the development of FSLeyes, I decided to retain these names to preserve compatibility with FSLView naming conventions.

The matplotlib.cm.register_cmap, and related functions, allowed built-in colour maps to be overridden, but these were deprecated in matplotlib 3.6. The replacement for these functions, the matplotlib.colormaps registry, disallows overriding of built-in colour maps.

The fsleyes_props.ColourMap property requires colour maps to be registered with matplotlib, and it is not feasible to remove this requirement. Fortunately, the fsleyes_props.ColourMap property has a feature whereby colour maps can be selected by either registered key, or by the ListedColormap.name attribute. So all I need to do to work around the new constraints in matplotlib are:

  1. Register the FSLeyes colour maps with matplotlib under a different name (e.g. fsleyes_hot instead of hot).
  2. When creating the ListedColormap instance, set its name to the FSLeyes key (e.g. ListedColorMap(cmap, name='hot')).

This allows the colour map to be selected with either fsleyes_hot or with hot, which effectively masks the built-in matplotlib hot colour map.

This requires a minor adjustment to the fsleyes_props.ColourMap property: fsl/fsleyes/props!61

Edited by Paul McCarthy

Merge request reports