Skip to content

FIX: Correct names of aliased cmaps #28116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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