8000 Rename 'Add' to 'sRGB_add' · matplotlib/matplotlib@b59850d · GitHub
[go: up one dir, main page]

Skip to content

Commit b59850d

Browse files
committed
Rename 'Add' to 'sRGB_add'
This renames the 'combination_mode' keywords from 'Add' and 'Sub' to 'sRGB_add' and 'sRGB_sub'. This change is intended to provide increased clarity if/when additional keywords are added.
1 parent 8c150d1 commit b59850d

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

lib/matplotlib/_cm_multivar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@
158158

159159
cmap_families = {
160160
'2VarAddA': MultivarColormap('2VarAddA', [cmaps['2VarAddA' + str(i)] for
161-
i in range(2)], 'Add'),
161+
i in range(2)], 'sRGB_add'),
162162
'2VarSubA': MultivarColormap('2VarSubA', [cmaps['2VarSubA' + str(i)] for
163-
i in range(2)], 'Sub'),
163+
i in range(2)], 'sRGB_sub'),
164164
'3VarAddA': MultivarColormap('3VarAddA', [cmaps['3VarAddA' + str(i)] for
165-
i in range(3)], 'Add'),
165+
i in range(3)], 'sRGB_add'),
166166
}

lib/matplotlib/colors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,12 +1267,12 @@ def __init__(self, name, colormaps, combination_mode):
12671267
The name of the colormap family.
12681268
colormaps: list or tuple of `~matplotlib.colors.Colormap` objects
12691269
The individual colormaps that are combined
1270-
combination_mode: str, 'Add' or 'Sub'
1270+
combination_mode: str, 'sRGB_add' or 'sRGB_sub'
12711271
Describe how colormaps are combined in sRGB space
12721272
1273-
- If 'Add' -> Mixing produces brighter colors
1273+
- If 'sRGB_add' -> Mixing produces brighter colors
12741274
`sRGB = cmap[0][X[0]] + cmap[1][x[1]] + ... + cmap[n-1][x[n-1]]`
1275-
- If 'Sub' -> Mixing produces darker colors
1275+
- If 'sRGB_sub' -> Mixing produces darker colors
12761276
`sRGB = cmap[0][X[0]] + cmap[1][x[1]] + ... + cmap[n-1][x[n-1]] - n + 1`
12771277
"""
12781278
self.name = name
@@ -1291,8 +1291,8 @@ def __init__(self, name, colormaps, combination_mode):
12911291
" Colormap or valid strings.")
12921292

12931293
self._colormaps = colormaps
1294-
if combination_mode not in ['Add', 'Sub']:
1295-
raise ValueError("Combination_mode must be 'Add' or 'Sub',"
1294+
if combination_mode not in ['sRGB_add', 'sRGB_sub']:
1295+
raise ValueError("Combination_mode must be 'sRGB_add' or 'sRGB_sub',"
12961296
f" {combination_mode!r} is not allowed.")
12971297
self._combination_mode = combination_mode
12981298
self.n_variates = len(colormaps)
@@ -1340,7 +1340,7 @@ def __call__(self, X, alpha=None, bytes=False, clip=True):
13401340
rgba[..., 3] *= sub_rgba[..., 3] # multiply alpha
13411341
mask_bad |= sub_mask_bad
13421342

1343-
if self.combination_mode == 'Sub':
1343+
if self.combination_mode == 'sRGB_sub':
13441344
rgba[..., :3] -= len(self) - 1
13451345

13461346
rgba[mask_bad] = self.get_bad()

lib/matplotlib/tests/test_multivariate_colormaps.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_bivariate_cmap_shapes():
4141
def test_multivar_creation():
4242
# test creation of a custom multivariate colorbar
4343
blues = mpl.colormaps['Blues']
44-
cmap = mpl.colors.MultivarColormap('custom', (blues, 'Oranges'), 'Sub')
44+
cmap = mpl.colors.MultivarColormap('custom', (blues, 'Oranges'), 'sRGB_sub')
4545
y, x = np.mgrid[0:3, 0:3]/2
4646
im = cmap((y, x))
4747
res = np.array([[[0.96862745, 0.94509804, 0.92156863, 1],
@@ -56,11 +56,11 @@ def test_multivar_creation():
5656
assert_allclose(im, res, atol=0.01)
5757

5858
with pytest.raises(ValueError, match="colormaps must be a list of"):
59-
cmap = mpl.colors.MultivarColormap('custom', (blues, [blues]), 'Sub')
59+
cmap = mpl.colors.MultivarColormap('custom', (blues, [blues]), 'sRGB_sub')
6060
with pytest.raises(ValueError, match="A MultivarColormap must"):
61-
cmap = mpl.colors.MultivarColormap('custom', 'blues', 'Sub')
61+
cmap = mpl.colors.MultivarColormap('custom', 'blues', 'sRGB_sub')
6262
with pytest.raises(ValueError, match="A MultivarColormap must"):
63-
cmap = mpl.colors.MultivarColormap('custom', (blues), 'Sub')
63+
cmap = mpl.colors.MultivarColormap('custom', (blues), 'sRGB_sub')
6464

6565

6666
@image_comparison(["multivar_alpha_mixing.png"])
@@ -72,7 +72,7 @@ def test_multivar_alpha_mixing():
7272
alpha[:, 3] = np.linspace(1, 0, 256)
7373
alpha_cmap = mpl.colors.LinearSegmentedColormap.from_list('from_list', alpha)
7474

75-
cmap = mpl.colors.MultivarColormap('custom', (rainbow, alpha_cmap), 'Add')
75+
cmap = mpl.colors.MultivarColormap('custom', (rainbow, alpha_cmap), 'sRGB_add')
7676
y, x = np.mgrid[0:10, 0:10]/9
7777
im = cmap((y, x))
7878

@@ -185,7 +185,7 @@ def test_multivar_cmap_call():
185185

186186
def test_multivar_bad_mode():
187187
cmap = mpl.multivar_colormaps['2VarSubA']
188-
with pytest.raises(ValueError, match="Combination_mode must be 'Add' or 'Sub'"):
188+
with pytest.raises(ValueError, match="Combination_mode must be 'sRGB_add' or"):
189189
cmap = mpl.colors.MultivarColormap('', cmap[:], 'bad')
190190

191191

@@ -508,7 +508,7 @@ def test_multivar_eq():
508508

509509
cmap_1 = mpl.colors.MultivarColormap('2VarAddA',
510510
[cmap_0[0]]*2,
511-
'Add')
511+
'sRGB_add')
512512
assert (cmap_0 == cmap_1) is False
513513

514514
cmap_1 = mpl.multivar_colormaps['3VarAddA']
@@ -519,5 +519,5 @@ def test_multivar_eq():
519519
assert (cmap_0 == cmap_1) is False
520520

521521
cmap_1 = mpl.multivar_colormaps['2VarAddA']
522-
cmap_1 = mpl.colors.MultivarColormap('', cmap_1[:], 'Sub')
522+
cmap_1 = mpl.colors.MultivarColormap('', cmap_1[:], 'sRGB_sub')
523523
assert (cmap_0 == cmap_1) is False

0 commit comments

Comments
 (0)
0