Skip to content

Commit

Permalink
FIX: Correct names of aliased cmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm committed Apr 22, 2024
1 parent 199c31f commit 2fc96d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ def _gen_cmap_registry():
colors.LinearSegmentedColormap.from_list(name, spec, _LUTSIZE))

# Register colormap aliases for gray and grey.
cmap_d['grey'] = cmap_d['gray']
cmap_d['gist_grey'] = cmap_d['gist_gray']
cmap_d['gist_yerg'] = cmap_d['gist_yarg']
cmap_d['Grays'] = cmap_d['Greys']
aliases = {
# alias -> original name
'grey': 'gray',
'gist_grey': 'gist_gray',
'gist_yerg': 'gist_yarg',
'Grays': 'Greys',
}
for alias, original_name in aliases.items():
cmap = cmap_d[original_name].copy()
cmap.name = alias
cmap_d[alias] = cmap

# Generate reversed cmaps.
for cmap in list(cmap_d.values()):
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,11 @@ def test_set_cmap_mismatched_name():
assert cmap_returned.name == "wrong-cmap"


def test_cmap_alias_names():
assert matplotlib.colormaps["gray"].name == "gray" # original
assert matplotlib.colormaps["grey"].name == "grey" # alias


def test_to_rgba_array_none_color_with_alpha_param():
# effective alpha for color "none" must always be 0 to achieve a vanishing color
# even explicit alpha must be ignored
Expand Down

0 comments on commit 2fc96d6

Please sign in to comment.