Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up matplotlib.colors #4149

Merged
merged 2 commits into from Mar 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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