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

Skip to content

Commit 266eac6

Browse files
committed
FIX: use left and right
1 parent 9ef1caa commit 266eac6

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

lib/matplotlib/colors.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,13 +1300,11 @@ def __call__(self, value, clip=None):
13001300

13011301
if not self.vmin <= self.vcenter <= self.vmax:
13021302
raise ValueError("vmin, vcenter, vmax must increase monotonically")
1303-
# must linearly extrapolate for ticks on colorbars that go
1304-
# beyond vmin and vmax:
1305-
min = self.vmin - (self.vcenter - self.vmin)
1306-
max = self.vmax + (self.vmax - self.vcenter)
1303+
# note that we must extrapolate for tick locators:
13071304
result = np.ma.masked_array(
1308-
np.interp(result, [min, self.vcenter, max],
1309-
[-0.5, 0.5, 1.5]), mask=np.ma.getmask(result))
1305+
np.interp(result, [self.vmin, self.vcenter, self.vmax],
1306+
[0, 0.5, 1], left=-np.inf, right=np.inf),
1307+
mask=np.ma.getmask(result))
13101308
if is_scalar:
13111309
result = np.atleast_1d(result)[0]
13121310
return result
@@ -1317,9 +1315,8 @@ def inverse(self, value):
13171315
(vmin,), _ = self.process_value(self.vmin)
13181316
(vmax,), _ = self.process_value(self.vmax)
13191317
(vcenter,), _ = self.process_value(self.vcenter)
1320-
min = vmin - (vcenter - vmin)
1321-
max = vmax + (vmax - vcenter)
1322-
result = np.interp(value, [-0.5, 0.5, 1.5], [min, vcenter, max])
1318+
result = np.interp(value, [0, 0.5, 1], [vmin, vcenter, vmax],
1319+
left=-np.inf, right=np.inf)
13231320
return result
13241321

13251322

tutorials/colors/colormapnorms.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,13 @@ def __call__(self, value, clip=None):
326326
# I'm ignoring masked values and all kinds of edge cases to make a
327327
# simple example...
328328
# Note also that we must extrapolate linearly beyond vmin/vmax
329-
min = self.vmin - (self.vcenter - self.vmin)
330-
max = self.vmax + (self.vmax - self.vcenter)
331-
x, y = [min, self.vcenter, max], [-0.5, 0.5, 1.5]
332-
return np.ma.masked_array(np.interp(value, x, y))
329+
x, y = [self.vmin, self.vcenter, self.vmax], [0, 0.5, 1.]
330+
return np.ma.masked_array(np.interp(value, x, y,
331+
left=-np.inf, right=np.inf))
333332

334333
def inverse(self, value):
335-
min = self.vmin - (self.vcenter - self.vmin)
336-
max = self.vmax + (self.vmax - self.vcenter)
337-
y, x = [min, self.vcenter, max], [-0.5, 0.5, 1.5]
338-
return np.interp(value, x, y)
334+
y, x = [self.vmin, self.vcenter, self.vmax], [0, 0.5, 1]
335+
return np.interp(value, x, y, left=-np.inf, right=np.inf)
339336

340337

341338
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)