Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d03552

Browse files
committed
Do 2D->1D mapping in call method of colormap
1 parent d54cb44 commit 4d03552

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/matplotlib/colors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ def __call__(self, X, alpha=None, bytes=False):
473473
xa = np.array([X])
474474
else:
475475
vtype = 'array'
476+
if isinstance(self, BivariateColormap):
477+
X[0] = X[0] * 256
478+
X[1] = X[1] * 256
479+
X = X.astype(int)
480+
X = X[0] + X[1] * 256
476481
xma = np.ma.array(X, copy=True) # Copy here to avoid side effects.
477482
mask_bad = xma.mask # Mask will be used below.
478483
xa = xma.filled() # Fill to avoid infs, etc.
@@ -1427,14 +1432,9 @@ def __call__(self, values, clip=None):
14271432
if clip is None:
14281433
clip = [self.norm1.clip, self.norm2.clip]
14291434

1430-
temp = np.asarray([self.norm1(values[0], clip=clip[0]),
1435+
return np.asarray([self.norm1(values[0], clip=clip[0]),
14311436
self.norm2(values[1], clip=clip[1])])
14321437

1433-
temp[0] = temp[0] * (256)
1434-
temp[1] = temp[1] * (256)
1435-
temp = temp.astype(int)
1436-
return temp[0] + temp[1] * 256
1437-
14381438
def autoscale(self, A):
14391439
"""
14401440
Set *vmin*, *vmax* to min, max of *A*.

lib/matplotlib/image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
375375
if A.ndim == 2 or (A.ndim == 3 and
376376
isinstance(self.norm, mcolors.BivariateNorm)):
377377
A = self.norm(A)
378-
if A.dtype.kind == 'f':
378+
if (A.dtype.kind == 'f' and
379+
not isinstance(self.norm, mcolors.BivariateNorm)):
379380
# If the image is greyscale, convert to RGBA and
380381
# use the extra channels for resizing the over,
381382
# under, and bad pixels. This is needed because
@@ -421,7 +422,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
421422

422423
if not created_rgba_mask:
423424
# Always convert to RGBA, even if only RGB input
424-
isBivari = (A.ndim == 2 and A.shape[0] == 2)
425+
isBivari = (A.ndim == 3 and A.shape[0] == 2)
425426
if A.shape[2] == 3:
426427
A = _rgb_to_rgba(A)
427428
elif A.shape[2] != 4 and not isBivari:

0 commit comments

Comments
 (0)