Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06452f1

Browse files
committed
Small edits suggested by tacaswell
1 parent 4ff1492 commit 06452f1

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

doc/users/colormapnorms.rst

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _colormapnorm-tutorial:
22

3-
Colormap Normaliztions
3+
Colormap Normaliztions
44
================================
55

66
Objects that use colormaps by default linearly map the colors in the
@@ -10,34 +10,36 @@ colormap from data values *vmin* to *vmax*. For example::
1010

1111
will map the data in *Z* linearly from -1 to +1, so *Z=0* will
1212
give a color at the center of the colormap *RdBu_r* (white in this
13-
case).
13+
case).
1414

1515
Matplotlib does this mapping in two steps, with a normalization from
1616
[0,1] occuring first, and then mapping onto the indices in the
1717
colormap. Normalizations are defined as part of
1818
:func:`matplotlib.colors` module. The default normalization is
19-
:func:`matplotlib.colors.Normalize`. The artists that map data to
19+
:func:`matplotlib.colors.Normalize`.
20+
21+
The artists that map data to
2022
color pass the arguments *vmin* and *vmax* to
2123
:func:`matplotlib.colors.Normalize`. We can substnatiate the
2224
normalization and see what it returns. In this case it returns 0.5:
2325

2426
.. ipython::
2527

2628
In [1]: import matplotlib as mpl
27-
29+
2830
In [2]: norm=mpl.colors.Normalize(vmin=-1.,vmax=1.)
29-
31+
3032
In [3]: norm(0.)
3133
Out[3]: 0.5
3234

3335
However, there are sometimes cases where it is useful to map data to
34-
colormaps in a non-linear fashion.
36+
colormaps in a non-linear fashion.
3537

3638
Logarithmic
3739
---------------------------------
3840

3941
One of the most common transformations is to plot data by taking its
40-
logarithm (to the base-10). This transofrmation is useful when there
42+
logarithm (to the base-10). This transformation is useful when there
4143
are changes across disparate scales that we still want to be able to
4244
see. Using :func:`colors.LogNorm` normalizes the data by
4345
:math:`log_{10}`. In the example below, there are two bumps, one much
@@ -78,7 +80,7 @@ argument *gamma* ( *gamma* == 1.0 will just yield the defalut linear
7880
normalization):
7981

8082
.. note::
81-
83+
8284
There should probably be a good reason for plotting the data using
8385
this type of transformation. Technical viewers are used to linear
8486
and logarithmic axes and data transformations. Power laws are less
@@ -89,6 +91,31 @@ normalization):
8991
.. plot:: users/plotting/examples/colormap_normalizations_power.py
9092
:include-source:
9193

94+
Discrete bounds
95+
---------------------------------
96+
97+
Another normaization that comes with matplolib is
98+
:func:`colors.BoundaryNorm`. In addition to *vmin* and *vmax*, this
99+
takes as arguments boundaries between which data is to be mapped. The
100+
colors are then linearly distributed between these "bounds". For
101+
instance, if:
102+
103+
.. ipython::
104+
105+
In [2]: import matplotlib.colors as colors
106+
107+
In [3]: bounds = np.array([-0.25, -0.125, 0, 0.5, 1])
108+
109+
In [4]: norm = colors.BoundaryNorm(boundaries=bounds, ncolors=4)
110+
111+
In [5]: print norm([-0.2,-0.15,-0.02, 0.3, 0.8, 0.99])
112+
[0 0 1 2 3 3]
113+
114+
Note unlike the other norms, this norm returns values from 0 to *ncolors*-1.
115+
116+
.. plot:: users/plotting/examples/colormap_normalizations_bounds.py
117+
:include-source:
118+
92119

93120
Custom normalization: Two linear ranges
94121
-----------------------------------------
@@ -104,29 +131,9 @@ for the edge cases like masked data or invalid values of *vmin* and
104131
This may appear soon as :func:`colors.OffsetNorm`
105132

106133
As above, non-symetric mapping of data to color is non-standard
107-
practice, and should only be used advisedly.
134+
practice for quantitative data, and should only be used advisedly. A
135+
practical example is having an ocean/land colormap where the land and
136+
ocean data span different ranges.
108137

109138
.. plot:: users/plotting/examples/colormap_normalizations_custom.py
110139
:include-source:
111-
112-
Discrete bounds
113-
---------------------------------
114-
115-
Another normaization that comes with matplolib is
116-
:func:`colors.BoundaryNorm`. In addition to *vmin* and *vmax*, this
117-
takes as arguments boundaries between which data is to be mapped. The
118-
colors are then linearly distributed between these "bounds". For
119-
instance, if ::
120-
121-
bounds = np.array([-0.25, -0.125, 0, 0.5, 1])
122-
norm = colors.BoundaryNorm(boundaries=bounds, ncolors=4)
123-
print norm([-0.2,-0.15,-0.02, 0.3, 0.8, 0.99])
124-
125-
This returns: [0, 0, 1, 2, 3, 3]. Note unlike the other norms, this
126-
norm returns values from 0 to *ncolors*-1.
127-
128-
129-
.. plot:: users/plotting/examples/colormap_normalizations_bounds.py
130-
:include-source:
131-
132-

0 commit comments

Comments
 (0)