Skip to content

Commit a7c3210

Browse files
authored
Merge pull request matplotlib#28116 from timhoffm/fix-cmap-alias-names
FIX: Correct names of aliased cmaps
2 parents eb62d69 + 2fc96d6 commit a7c3210

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/matplotlib/cm.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,17 @@ def _gen_cmap_registry():
4444
colors.LinearSegmentedColormap.from_list(name, spec, _LUTSIZE))
4545

4646
# Register colormap aliases for gray and grey.
47-
cmap_d['grey'] = cmap_d['gray']
48-
cmap_d['gist_grey'] = cmap_d['gist_gray']
49-
cmap_d['gist_yerg'] = cmap_d['gist_yarg']
50-
cmap_d['Grays'] = cmap_d['Greys']
47+
aliases = {
48+
# alias -> original name
49+
'grey': 'gray',
50+
'gist_grey': 'gist_gray',
51+
'gist_yerg': 'gist_yarg',
52+
'Grays': 'Greys',
53+
}
54+
for alias, original_name in aliases.items():
55+
cmap = cmap_d[original_name].copy()
56+
cmap.name = alias
57+
cmap_d[alias] = cmap
5158

5259
# Generate reversed cmaps.
5360
for cmap in list(cmap_d.values()):

lib/matplotlib/tests/test_colors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,11 @@ def test_set_cmap_mismatched_name():
16891689
assert cmap_returned.name == "wrong-cmap"
16901690

16911691

1692+
def test_cmap_alias_names():
1693+
assert matplotlib.colormaps["gray"].name == "gray" # original
1694+
assert matplotlib.colormaps["grey"].name == "grey" # alias
1695+
1696+
16921697
def test_to_rgba_array_none_color_with_alpha_param():
16931698
# effective alpha for color "none" must always be 0 to achieve a vanishing color
16941699
# even explicit alpha must be ignored

0 commit comments

Comments
 (0)