8000 FIX: Correct names of aliased cmaps · matplotlib/matplotlib@2fc96d6 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2fc96d6

Browse files
committed
FIX: Correct names of aliased cmaps
Closes #28114.
1 parent 199c31f commit 2fc96d6

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)
0