@@ -922,27 +922,32 @@ def reversed(self, name=None):
922
922
923
923
class Normalize :
924
924
"""
925
- A class which, when called, can normalize data into
926
- the ``[0.0, 1.0]`` interval.
927
-
925
+ A class which, when called, linearly normalizes data into the
926
+ ``[0.0, 1.0]`` interval.
928
927
"""
929
928
def __init__ (self , vmin = None , vmax = None , clip = False ):
930
929
"""
931
- If *vmin* or *vmax* is not given, they are initialized from the
930
+ Parameters
931
+ ----------
932
+ vmin : scalar
933
+ vmax : scalar
934
+ clip : bool
935
+ If ``True`` values falling outside the range ``[vmin, vmax]``,
936
+ are mapped to 0 or 1, whichever is closer, and masked values are
937
+ set to 1. If ``False`` masked values remain masked.
938
+
939
+ Notes
940
+ -----
941
+ If neither *vmin* or *vmax* are given, they are initialized from the
932
942
minimum and maximum value respectively of the first input
933
- processed. That is, *__call__(A)* calls *autoscale_None(A)*.
934
- If *clip* is *True* and the given value falls outside the range,
935
- the returned value will be 0 or 1, whichever is closer.
936
- Returns 0 if ::
943
+ processed. That is, ``__call__(A)`` calls ``autoscale_None(A)``.
944
+ Returns 0 if::
937
945
938
946
vmin==vmax
939
947
940
- Works with scalars or arrays, including masked arrays. If
941
- *clip* is *True*, masked values are set to 1; otherwise they
942
- remain masked. Clipping silently defeats the purpose of setting
943
- the over, under, and masked colors in the colormap, so it is
944
- likely to lead to surprises; therefore the default is
945
- *clip* = *False*.
948
+ Clipping silently defeats the purpose of setting the over, under, and
949
+ masked colors in a colormap, so it is likely to lead to surprises;
950
+ therefore the default is ``clip=False``.
946
951
"""
947
952
self .vmin = _sanitize_extrema (vmin )
948
953
self .vmax = _sanitize_extrema (vmax )
@@ -955,15 +960,19 @@ def process_value(value):
955
960
956
961
*value* can be a scalar or sequence.
957
962
958
- Returns *result*, *is_scalar*, where *result* is a
959
- masked array matching *value*. Float dtypes are preserved;
960
- integer types with two bytes or smaller are converted to
961
- np.float32, and larger types are converted to np.float64 .
962
- Preserving float32 when possible, and using in-place operations,
963
- can greatly improve speed for large arrays .
963
+ Returns
964
+ -------
965
+ result : masked array
966
+ Masked array with the same shape as *value* .
967
+ is_scalar : bool
968
+ ``True`` if *value* is a scalar .
964
969
965
- Experimental; we may want to add an option to force the
966
- use of float32.
970
+ Notes
971
+ -----
972
+ Float dtypes are preserved; integer types with two bytes or smaller are
973
+ converted to np.float32, and larger types are converted to np.float64.
974
+ Preserving float32 when possible, and using in-place operations,
975
+ greatly improves speed for large arrays.
967
976
"""
968
977
is_scalar = not np .iterable (value )
969
978
if is_scalar :
@@ -981,11 +990,21 @@ def process_value(value):
981
990
982
991
def __call__ (self , value , clip = None ):
983
992
"""
984
- Normalize *value* data in the ``[vmin, vmax]`` interval into
985
- the ``[0.0, 1.0]`` interval and return it. *clip* defaults
986
- to ``self.clip`` (which defaults to *False*). If not already
987
- initialized, *vmin* and *vmax* are initialized using
988
- ``autoscale_None(value)``.
993
+ Normalize *value* data in the ``[vmin, vmax]`` interval into the
994
+ ``[0.0, 1.0]`` interval and return it.
995
+
996
+ Parameters
997
+ ----------
998
+ value
999
+ Data to normalize.
1000
+ clip : bool
1001
+ If ``None``, defaults to ``self.clip`` (which defaults to
1002
+ ``False``).
1003
+
1004
+ Notes
1005
+ -----
1006
+ If not already initialized, ``self.vmin`` and ``self.vmax`` are
1007
+ initialized using ``self.autoscale_None(value)``.
989
1008
"""
990
1009
if clip is None :
991
1010
clip = self .clip
@@ -1016,7 +1035,7 @@ def __call__(self, value, clip=None):
1016
1035
1017
1036
def inverse (self , value ):
1018
1037
if not self .scaled ():
1019
- raise ValueError ("Not invertible until scaled " )
1038
+ raise ValueError ("Not invertible until both vmin and vmax are set " )
1020
1039
(vmin ,), _ = self .process_value (self .vmin )
1021
1040
(vmax ,), _ = self .process_value (self .vmax )
1022
1041
@@ -1033,7 +1052,7 @@ def autoscale(self, A):
1033
1052
self .vmax = A .max ()
1034
1053
1035
1054
def autoscale_None (self , A ):
1036
- """Autoscale only None-valued vmin or vmax."""
1055
+ """If vmin or vmax are not set, use the min/max of *A* to set them ."""
1037
1056
A = np .asanyarray (A )
1038
1057
if self .vmin is None and A .size :
1039
1058
self .vmin = A .min ()
@@ -1194,7 +1213,7 @@ class SymLogNorm(Normalize):
1194
1213
*linthresh* allows the user to specify the size of this range
1195
1214
(-*linthresh*, *linthresh*).
1196
1215
"""
1197
- def __init__ (self , linthresh , linscale = 1.0 ,
1216
+ def __init__ (self , linthresh , linscale = 1.0 ,
1198
1217
vmin = None , vmax = None , clip = False ):
1199
1218
"""
1200
1219
Parameters
0 commit comments