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

Appearance settings

Commit 47cfa35

Browse filesBrowse files
authored
Clean up and clarify Normalize docs (#16271)
Clean up and clarify Normalize docs
2 parents 482d30a + 653c2cf commit 47cfa35
Copy full SHA for 47cfa35

File tree

Expand file treeCollapse file tree

1 file changed

+49
-30
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+49
-30
lines changed

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+49-30Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -922,27 +922,32 @@ def reversed(self, name=None):
922922

923923
class Normalize:
924924
"""
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.
928927
"""
929928
def __init__(self, vmin=None, vmax=None, clip=False):
930929
"""
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
932942
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::
937945
938946
vmin==vmax
939947
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``.
946951
"""
947952
self.vmin = _sanitize_extrema(vmin)
948953
self.vmax = _sanitize_extrema(vmax)
@@ -955,15 +960,19 @@ def process_value(value):
955960
956961
*value* can be a scalar or sequence.
957962
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.
964969
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.
967976
"""
968977
is_scalar = not np.iterable(value)
969978
if is_scalar:
@@ -981,11 +990,21 @@ def process_value(value):
981990

982991
def __call__(self, value, clip=None):
983992
"""
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)``.
9891008
"""
9901009
if clip is None:
9911010
clip = self.clip
@@ -1016,7 +1035,7 @@ def __call__(self, value, clip=None):
10161035

10171036
def inverse(self, value):
10181037
if not self.scaled():
1019-
raise ValueError("Not invertible until scaled")
1038+
raise ValueError("Not invertible until both vmin and vmax are set")
10201039
(vmin,), _ = self.process_value(self.vmin)
10211040
(vmax,), _ = self.process_value(self.vmax)
10221041

@@ -1033,7 +1052,7 @@ def autoscale(self, A):
10331052
self.vmax = A.max()
10341053

10351054
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."""
10371056
A = np.asanyarray(A)
10381057
if self.vmin is None and A.size:
10391058
self.vmin = A.min()
@@ -1194,7 +1213,7 @@ class SymLogNorm(Normalize):
11941213
*linthresh* allows the user to specify the size of this range
11951214
(-*linthresh*, *linthresh*).
11961215
"""
1197-
def __init__(self, linthresh, linscale=1.0,
1216+
def __init__(self, linthresh, linscale=1.0,
11981217
vmin=None, vmax=None, clip=False):
11991218
"""
12001219
Parameters

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.