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

Skip to content

Commit 4e440af

Browse files
committed
Clean up makeMappingArray
1 parent 917efaa commit 4e440af

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/matplotlib/colors.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def makeMappingArray(N, data, gamma=1.0):
457457
except:
458458
raise TypeError("data must be convertable to an array")
459459
shape = adata.shape
460-
if len(shape) != 2 and shape[1] != 3:
460+
if len(shape) != 2 or shape[1] != 3:
461461
raise ValueError("data must be nx3 format")
462462

463463
x = adata[:, 0]
@@ -476,13 +476,12 @@ def makeMappingArray(N, data, gamma=1.0):
476476
xind = (N - 1) * np.linspace(0, 1, N) ** gamma
477477
ind = np.searchsorted(x, xind)[1:-1]
478478

479-
lut[1:-1] = (((xind[1:-1] - x[ind - 1]) / (x[ind] - x[ind - 1])) *
480-
(y0[ind] - y1[ind - 1]) + y1[ind - 1])
479+
distance = (xind[1:-1] - x[ind - 1]) / (x[ind] - x[ind - 1])
480+
lut[1:-1] = distance * (y0[ind] - y1[ind - 1]) + y1[ind - 1]
481481
lut[0] = y1[0]
482482
lut[-1] = y0[-1]
483483
# ensure that the lut is confined to values between 0 and 1 by clipping it
484-
np.clip(lut, 0.0, 1.0)
485-
return lut
484+
return np.clip(lut, 0.0, 1.0)
486485

487486

488487
class Colormap(object):

0 commit comments

Comments
 (0)