Skip to content

Commit

Permalink
Merge pull request #1260 from efiring/boundary_norm_interp
Browse files Browse the repository at this point in the history
Fix BoundaryNorm interpolation with numpy 1.7rc.
  • Loading branch information
WeatherGod committed Sep 17, 2012
2 parents 0a8a110 + 1a0f05a commit ab3e42f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/matplotlib/colors.py
Expand Up @@ -1056,8 +1056,8 @@ def __call__(self, x, clip=None):
for i, b in enumerate(self.boundaries):
iret[xx >= b] = i
if self._interp:
iret *= float(self.Ncmap - 1) / (self.N - 2)
iret = iret.astype(np.int16)
scalefac = float(self.Ncmap - 1) / (self.N - 2)
iret = (iret * scalefac).astype(np.int16)
iret[xx < self.vmin] = -1
iret[xx >= self.vmax] = self.Ncmap
ret = ma.array(iret, mask=mask)
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Expand Up @@ -23,4 +23,17 @@ def test_colormap_endian():
#print(anative.dtype.isnative, aforeign.dtype.isnative)
assert_array_equal(cmap(anative), cmap(aforeign))

def test_BoundaryNorm():
"""
Github issue #1258: interpolation was failing with numpy
1.7 pre-release.
"""
# TODO: expand this into a more general test of BoundaryNorm.
boundaries = [0, 1.1, 2.2]
vals = [-1, 0, 2, 2.2, 4]
expected = [-1, 0, 2, 3, 3]
# ncolors != len(boundaries) - 1 triggers interpolation
ncolors = len(boundaries)
bn = mcolors.BoundaryNorm(boundaries, ncolors)
assert_array_equal(bn(vals), expected)

0 comments on commit ab3e42f

Please sign in to comment.