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

Skip to content

Commit fc8ce8c

Browse files
committed
Return 0.5 for vcenter == vmax
np.interp handles the case vmin == vcenter, we have to add a special case to make the last test case pass
1 parent b069a94 commit fc8ce8c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/matplotlib/colors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,10 +1021,14 @@ def __call__(self, value, clip=None):
10211021
vmin = float(vmin)
10221022
vcenter = float(vcenter)
10231023
vmax = float(vmax)
1024+
# in degenerate cases, prefer the center value to the extremes
1025+
degen = (result == vcenter) if vcenter == vmax else None
10241026

10251027
x, y = [vmin, vcenter, vmax], [0, 0.5, 1]
10261028
result = ma.masked_array(np.interp(result, x, y),
10271029
mask=ma.getmask(result))
1030+
if degen is not None:
1031+
result[degen] = 0.5
10281032

10291033
if is_scalar:
10301034
result = np.atleast_1d(result)[0]

0 commit comments

Comments
 (0)