8000 BUG : fix PowerNorm with scalars by tacaswell · Pull Request #4055 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

BUG : fix PowerNorm with scalars #4055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 1, 2015
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
BUG : fix PowerNorm with scalars
closes #4053
  • Loading branch information
tacaswell committed Jan 30, 2015
commit c98a90d192bced1671024098726988e5d9b0c8ac
4 changes: 3 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ def __call__(self, value, clip=None):
elif vmin == vmax:
result.fill(0)
else:
res_mask = result.data < 0
if clip:
mask = ma.getmask(result)
val = ma.array(np.clip(result.filled(vmax), vmin, vmax),
Expand All @@ -1176,8 +1177,9 @@ def __call__(self, value, clip=None):
resdat -= vmin
np.power(resdat, gamma, resdat)
resdat /= (vmax - vmin) ** gamma

result = np.ma.array(resdat, mask=result.mask, copy=False)
result[value < 0] = 0
result[res_mask] = 0
if is_scalar:
result = result[0]
return result
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import six

from nose.tools import assert_raises
from nose.tools import assert_raises, assert_equal

import numpy as np
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
Expand Down Expand Up @@ -62,9 +62,11 @@ def test_PowerNorm():
assert_array_almost_equal(norm(a), pnorm(a))

a = np.array([-0.5, 0, 2, 4, 8], dtype=np.float)
expected = [0, 0, 1./16, 1./4, 1]
expected = [0, 0, 1/16, 1/4, 1]
pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
assert_array_almost_equal(pnorm(a), expected)
assert_equal(pnorm(a[0]), expected[0])
assert_equal(pnorm(a[2]), expected[2])
assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])


Expand Down
0