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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don't convert vmin, vmax to floats.
They may be float128's in which case precision would be lost; this can
result in `Normalize` returning values (barely) outside of `[0, 1]`.

(The cast to `float` was introduced in 28e1d2, referring to bug 2997687
on SF; it may be worth checking what it was about.)
  • Loading branch information
anntzer committed Jul 7, 2016
commit 16f9778c6727531b4c06e407648c0c16e1a6ae3c
5 changes: 1 addition & 4 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,6 @@ def __call__(self, value, clip=None):
elif vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
else:
vmin = float(vmin)
vmax = float(vmax)
if clip:
mask = np.ma.getmask(result)
result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax),
Expand All @@ -938,8 +936,7 @@ def __call__(self, value, clip=None):
def inverse(self, value):
if not self.scaled():
raise ValueError("Not invertible until scaled")
vmin = float(self.vmin)
vmax = float(self.vmax)
vmin, vmax = self.vmin, self.vmax

if cbook.iterable(value):
val = np.ma.asarray(value)
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def test_Normalize():
_scalar_tester(norm, vals)
_mask_tester(norm, vals)

# Don't lose precision on longdoubles (float128 on Linux).
vals = np.array([1.2345678901, 9.8765432109], dtype=np.longdouble)
norm = mcolors.Normalize(vals.min(), vals.max())
assert_array_equal(np.asarray(norm(vals)), [0, 1])


def test_SymLogNorm():
"""
Expand Down