Skip to content

Commit

Permalink
Merge pull request #4149 from alanhdu/master
Browse files Browse the repository at this point in the history
Clean up matplotlib.colors
  • Loading branch information
efiring committed Mar 1, 2015
2 parents 917efaa + 9c3623a commit 793e52a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/matplotlib/colors.py
Expand Up @@ -457,7 +457,7 @@ def makeMappingArray(N, data, gamma=1.0):
except:
raise TypeError("data must be convertable to an array")
shape = adata.shape
if len(shape) != 2 and shape[1] != 3:
if len(shape) != 2 or shape[1] != 3:
raise ValueError("data must be nx3 format")

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

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


class Colormap(object):
Expand Down Expand Up @@ -1196,7 +1195,7 @@ def inverse(self, value):

if cbook.iterable(value):
val = ma.asarray(value)
return ma.power(value, 1. / gamma) * (vmax - vmin) + vmin
return ma.power(val, 1. / gamma) * (vmax - vmin) + vmin
else:
return pow(value, 1. / gamma) * (vmax - vmin) + vmin

Expand Down Expand Up @@ -1551,8 +1550,7 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
aspect = np.arctan2(-dy, -dx)
slope = 0.5 * np.pi - np.arctan(np.hypot(dx, dy))
intensity = (np.sin(alt) * np.sin(slope) +
np.cos(alt) * np.cos(slope) *
np.cos(az - aspect))
np.cos(alt) * np.cos(slope) * np.cos(az - aspect))

# Apply contrast stretch
imin, imax = intensity.min(), intensity.max()
Expand Down

0 comments on commit 793e52a

Please sign in to comment.