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

Skip to content

Commit 04ea107

Browse files
phobsonOceanWolf
authored andcommitted
removed OffsetNorm.inverse method
This will allow the ticks of colors to be spaced as desired. Also simplified the math per the brilliant @joferkington http://stackoverflow.com/a/20146989/1552748
1 parent 03e506c commit 04ea107

File tree

1 file changed

+2
-34
lines changed

1 file changed

+2
-34
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,46 +1033,14 @@ def __call__(self, value, clip=None):
10331033
result = ma.array(np.clip(result.filled(vmax), vmin, vmax),
10341034
mask=mask)
10351035

1036-
# ma division is very slow; we can take a shortcut
1037-
resdat = result.data
1038-
1039-
#First scale to -1 to 1 range, than to from 0 to 1.
1040-
resdat -= vcenter
1041-
resdat[resdat > 0] /= abs(vmax - vcenter)
1042-
resdat[resdat < 0] /= abs(vmin - vcenter)
1043-
1044-
resdat /= 2.
1045-
resdat += 0.5
1046-
result = np.ma.array(resdat, mask=result.mask, copy=False)
1036+
x, y = [vmin, vcenter, vmax], [0, 0.5, 1]
1037+
result = np.ma.masked_array(np.interp(value, x, y))
10471038

10481039
if is_scalar:
10491040
result = result[0]
10501041

10511042
return result
10521043

1053-
def inverse(self, value):
1054-
if not self.scaled():
1055-
raise ValueError("Not invertible until scaled")
1056-
1057-
vmin, vcenter, vmax = self.vmin, self.vcenter, self.vmax
1058-
vmin = float(self.vmin)
1059-
vcenter = float(self.vcenter)
1060-
vmax = float(self.vmax)
1061-
1062-
if cbook.iterable(value):
1063-
val = ma.asarray(value)
1064-
val = 2 * (val - 0.5)
1065-
val[val > 0] *= abs(vmax - vcenter)
1066-
val[val < 0] *= abs(vmin - vcenter)
1067-
val += vcenter
1068-
return val
1069-
else:
1070-
val = 2 * (val - 0.5)
1071-
if val < 0:
1072-
return val * abs(vmin - vcenter) + vcenter
1073-
else:
1074-
return val * abs(vmax - vcenter) + vcenter
1075-
10761044
def autoscale_None(self, A):
10771045
' autoscale only None-valued vmin or vmax'
10781046
if self.vmin is None and np.size(A) > 0:

0 commit comments

Comments
 (0)