@@ -1215,36 +1215,55 @@ def reversed(self, name=None):
1215
1215
1216
1216
class Normalize :
1217
1217
"""
1218
- A class which, when called, linearly normalizes data into the
1219
- ``[0.0, 1.0]`` interval.
1218
+ A class which, when called, maps values within the interval
1219
+ ``[vmin, vmax]`` linearly to the interval ``[0.0, 1.0]``. The mapping of
1220
+ values outside ``[vmin, vmax]`` depends on *clip*.
1221
+
1222
+ Examples
1223
+ --------
1224
+ ::
1225
+
1226
+ x = [-2, -1, 0, 1, 2]
1227
+
1228
+ norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=False)
1229
+ norm(x) # [-0.5, 0., 0.5, 1., 1.5]
1230
+ norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=True)
1231
+ norm(x) # [0., 0., 0.5, 1., 1.]
1232
+
1233
+ See Also
1234
+ --------
1235
+ :ref:`colormapnorms`
1220
1236
"""
1221
1237
1222
1238
def __init__ (self , vmin = None , vmax = None , clip = False ):
1223
1239
"""
1224
1240
Parameters
1225
1241
----------
1226
1242
vmin, vmax : float or None
1227
- If *vmin* and/or *vmax* is not given, they are initialized from the
1228
- minimum and maximum value, respectively, of the first input
1229
- processed; i.e., ``__call__(A)`` calls ``autoscale_None(A)``.
1243
+ Values within the range ``[vmin, vmax]`` from the input data will be
1244
+ linearly mapped to ``[0, 1]``. If either *vmin* or *vmax* is not
1245
+ provided, they default to the minimum and maximum values of the input,
1246
+ respectively.
1247
+
1230
1248
1231
1249
clip : bool, default: False
1232
1250
Determines the behavior for mapping values outside the range
1233
1251
``[vmin, vmax]``.
1234
1252
1235
- If clipping is off , values outside the range ``[vmin, vmax]`` are also
1236
- transformed linearly, resulting in values outside ``[0, 1]``. For a
1237
- standard use with colormaps, this behavior is desired because colormaps
1238
- mark these outside values with specific colors for * over* or * under* .
1253
+ If *clip* is ``False`` , values outside ``[vmin, vmax]`` are also transformed
1254
+ linearly, leading to results outside ``[0, 1]``. For a standard use with
1255
+ colormaps, this behavior is desired because colormaps mark these outside
1256
+ values with specific colors for over or under.
1239
1257
1240
- If ``True`` values falling outside the range ``[vmin, vmax]``,
1241
- are mapped to 0 or 1, whichever is closer. This makes these values
1258
+ If *clip* is ``True``, values outside ``[vmin, vmax]`` are set to 0 or 1 ,
1259
+ depending on which boundary they're closer to . This makes these values
1242
1260
indistinguishable from regular boundary values and can lead to
1243
1261
misinterpretation of the data.
1244
1262
1263
+
1245
1264
Notes
1246
1265
-----
1247
- Returns 0 if ``vmin == vmax``.
1266
+ If ``vmin == vmax``, input data will be mapped to 0 .
1248
1267
"""
1249
1268
self ._vmin = _sanitize_extrema (vmin )
1250
1269
self ._vmax = _sanitize_extrema (vmax )
@@ -1298,6 +1317,11 @@ def process_value(value):
1298
1317
1299
1318
*value* can be a scalar or sequence.
1300
1319
1320
+ Parameters
1321
+ ----------
1322
+ value
1323
+ Data to normalize.
1324
+
1301
1325
Returns
1302
1326
-------
1303
1327
result : masked array
@@ -1328,8 +1352,7 @@ def process_value(value):
1328
1352
1329
1353
def __call__ (self , value , clip = None ):
1330
1354
"""
1331
- Normalize *value* data in the ``[vmin, vmax]`` interval into the
1332
- ``[0.0, 1.0]`` interval and return it.
1355
+ Normalize the data and return the normalized data.
1333
1356
1334
1357
Parameters
1335
1358
----------
@@ -1375,6 +1398,15 @@ def __call__(self, value, clip=None):
1375
1398
return result
1376
1399
1377
1400
def inverse (self , value ):
1401
+ """
1402
+ Maps the normalized value (i.e., index in the colormap) back to image
1403
+ data value.
1404
+
1405
+ Parameters
1406
+ ----------
1407
+ value
1408
+ Normalized value.
1409
+ """
1378
1410
if not self .scaled ():
1379
1411
raise ValueError ("Not invertible until both vmin and vmax are set" )
1380
1412
(vmin ,), _ = self .process_value (self .vmin )
@@ -1396,7 +1428,7 @@ def autoscale(self, A):
1396
1428
self ._changed ()
1397
1429
1398
1430
def autoscale_None (self , A ):
1399
- """If vmin or vmax are not set, use the min/max of *A* to set them."""
1431
+ """If * vmin* or * vmax* are not set, use the min/max of *A* to set them."""
1400
1432
A = np .asanyarray (A )
1401
1433
1402
1434
if isinstance (A , np .ma .MaskedArray ):
@@ -1410,7 +1442,7 @@ def autoscale_None(self, A):
1410
1442
self .vmax = A .max ()
1411
1443
1412
1444
def scaled (self ):
1413
- """Return whether vmin and vmax are set."""
1445
+ """Return whether * vmin* and * vmax* are both set."""
1414
1446
return self .vmin is not None and self .vmax is not None
1415
1447
1416
1448
0 commit comments