Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitacf92c6

Browse files
committed
Mask values < vmin in PowerNorm
1 parent2b05ace commitacf92c6

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``PowerNorm`` clipping
2+
~~~~~~~~~~~~~~~~~~~~~~
3+
When ``clip=False`` (the default) was set on `~.PowerNorm`, values
4+
less than ``vmin`` were previously clipped to zero without being masked.
5+
This has been fixed to mask these values in the result.

‎lib/matplotlib/colors.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,12 +1885,16 @@ def __call__(self, value, clip=None):
18851885
result=np.ma.array(np.clip(result.filled(vmax),vmin,vmax),
18861886
mask=mask)
18871887
resdat=result.data
1888-
resdat-=vmin
1889-
resdat[resdat<0]=0
1890-
np.power(resdat,gamma,resdat)
1891-
resdat/= (vmax-vmin)**gamma
1888+
# These values are masked later, but set to zero now to prevent
1889+
# invalid value warnings when taking the power
1890+
under_mask=resdat<vmin
1891+
resdat[under_mask]=vmin
18921892

1893-
result=np.ma.array(resdat,mask=result.mask,copy=False)
1893+
resdat= (resdat-vmin)/ (vmax-vmin)
1894+
resdat=resdat**gamma
1895+
1896+
mask=result.mask|under_mask
1897+
result=np.ma.array(resdat,mask=mask,copy=False)
18941898
ifis_scalar:
18951899
result=result[0]
18961900
returnresult

‎lib/matplotlib/tests/test_colors.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,16 @@ def test_PowerNorm():
551551
assert_array_almost_equal(norm(a),pnorm(a))
552552

553553
a=np.array([-0.5,0,2,4,8],dtype=float)
554-
expected= [0,0,1/16,1/4,1]
555554
pnorm=mcolors.PowerNorm(2,vmin=0,vmax=8)
556-
assert_array_almost_equal(pnorm(a),expected)
557-
assertpnorm(a[0])==expected[0]
555+
expected= [0,0,1/16,1/4,1]
556+
expected_mask= [True,False,False,False,False]
557+
558+
normed=pnorm(a)
559+
assert_array_almost_equal(normed,expected)
560+
assert_array_equal(normed.mask,expected_mask)
561+
assertpnorm(a[1])==expected[1]
558562
assertpnorm(a[2])==expected[2]
563+
559564
assert_array_almost_equal(a[1:],pnorm.inverse(pnorm(a))[1:])
560565

561566
# Clip = True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp