47
47
from collections import Sized
48
48
import itertools
49
49
import re
50
- import warnings
51
50
52
51
import numpy as np
53
52
import matplotlib .cbook as cbook
@@ -1170,8 +1169,8 @@ def autoscale_None(self, A):
1170
1169
1171
1170
class PowerNorm (Normalize ):
1172
1171
"""
1173
- Normalize a given value to the ``[0, 1]`` interval with a power-law
1174
- scaling. This will clip any negative data points to 0 .
1172
+ Linearly map a given value to the 0-1 range and then apply
1173
+ a power-law normalization over that range .
1175
1174
"""
1176
1175
def __init__ (self , gamma , vmin = None , vmax = None , clip = False ):
1177
1176
Normalize .__init__ (self , vmin , vmax , clip )
@@ -1191,18 +1190,17 @@ def __call__(self, value, clip=None):
1191
1190
elif vmin == vmax :
1192
1191
result .fill (0 )
1193
1192
else :
1194
- res_mask = result .data < 0
1195
1193
if clip :
1196
1194
mask = np .ma .getmask (result )
1197
1195
result = np .ma .array (np .clip (result .filled (vmax ), vmin , vmax ),
1198
1196
mask = mask )
1199
1197
resdat = result .data
1200
1198
resdat -= vmin
1199
+ resdat [resdat < 0 ] = 0
1201
1200
np .power (resdat , gamma , resdat )
1202
1201
resdat /= (vmax - vmin ) ** gamma
1203
1202
1204
1203
result = np .ma .array (resdat , mask = result .mask , copy = False )
1205
- result [res_mask ] = 0
1206
1204
if is_scalar :
1207
1205
result = result [0 ]
1208
1206
return result
@@ -1224,21 +1222,13 @@ def autoscale(self, A):
1224
1222
Set *vmin*, *vmax* to min, max of *A*.
1225
1223
"""
1226
1224
self .vmin = np .ma .min (A )
1227
- if self .vmin < 0 :
1228
- self .vmin = 0
1229
- warnings .warn ("Power-law scaling on negative values is "
1230
- "ill-defined, clamping to 0." )
1231
1225
self .vmax = np .ma .max (A )
1232
1226
1233
1227
def autoscale_None (self , A ):
1234
1228
"""autoscale only None-valued vmin or vmax."""
1235
1229
A = np .asanyarray (A )
1236
1230
if self .vmin is None and A .size :
1237
1231
self .vmin = A .min ()
1238
- if self .vmin < 0 :
1239
- self .vmin = 0
1240
- warnings .warn ("Power-law scaling on negative values is "
1241
- "ill-defined, clamping to 0." )
1242
1232
if self .vmax is None and A .size :
1243
1233
self .vmax = A .max ()
1244
1234
0 commit comments