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

Skip to content

Commit 7b34dc1

Browse files
committed
Tentative norm docs.
1 parent d6f86c1 commit 7b34dc1

File tree

8 files changed

+74
-145
lines changed

8 files changed

+74
-145
lines changed

doc/users/next_whats_new/strnorm.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Setting norms with strings
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Norms can now be set (e.g. on images) using the string name of the
4+
corresponding scale, e.g. ``imshow(array, norm="log")``. Note that in that
5+
case, it is permissible to also pass *vmin* and *vmax*, as a new Norm instance
6+
will be created under the hood.

lib/matplotlib/axes/_axes.py

Lines changed: 44 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,21 +4369,10 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43694369
See :mod:`matplotlib.markers` for more information about marker
43704370
styles.
43714371
4372-
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
4373-
A `.Colormap` instance or registered colormap name. *cmap* is only
4374-
used if *c* is an array of floats.
4375-
4376-
norm : `~matplotlib.colors.Normalize`, default: None
4377-
If *c* is an array of floats, *norm* is used to scale the color
4378-
data, *c*, in the range 0 to 1, in order to map into the colormap
4379-
*cmap*.
4380-
If *None*, use the default `.colors.Normalize`.
4381-
4382-
vmin, vmax : float, default: None
4383-
*vmin* and *vmax* are used in conjunction with the default norm to
4384-
map the color array *c* to the colormap *cmap*. If None, the
4385-
respective min and max of the color array is used.
4386-
It is an error to use *vmin*/*vmax* when *norm* is given.
4372+
cmap, norm, vmin, vmax
4373+
Data normalization and colormapping parameters for *c*; only used
4374+
if *c* is an array of floats. See `~.Axes.imshow` for a detailed
4375+
description.
43874376
43884377
alpha : float, default: None
43894378
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -4656,21 +4645,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
46564645
46574646
Other Parameters
46584647
----------------
4659-
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
4660-
The Colormap instance or registered colormap name used to map
4661-
the bin values to colors.
4662-
4663-
norm : `~matplotlib.colors.Normalize`, optional
4664-
The Normalize instance scales the bin values to the canonical
4665-
colormap range [0, 1] for mapping to colors. By default, the data
4666-
range is mapped to the colorbar range using linear scaling.
4667-
4668-
vmin, vmax : float, default: None
4669-
The colorbar range. If *None*, suitable min/max values are
4670-
automatically chosen by the `.Normalize` instance (defaults to
4671-
the respective min/max values of the bins in case of the default
4672-
linear scaling).
4673-
It is an error to use *vmin*/*vmax* when *norm* is given.
4648+
cmap, norm, vmin, vmax
4649+
Data normalization and colormapping parameters. See `~.Axes.imshow`
4650+
for a detailed description.
46744651
46754652
alpha : float between 0 and 1, optional
46764653
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -5296,6 +5273,10 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
52965273
replace_names=["y", "x1", "x2", "where"])
52975274

52985275
#### plotting z(x, y): imshow, pcolor and relatives, contour
5276+
5277+
# Once this deprecation elapses, also move vmin, vmax right after norm, to
5278+
# match the signature of other methods returning ScalarMappables and keep
5279+
# the documentation for *norm*, *vmax* and *vmin* together.
52995280
@_api.make_keyword_only("3.5", "aspect")
53005281
@_preprocess_data()
53015282
def imshow(self, X, cmap=None, norm=None, aspect=None,
@@ -5340,12 +5321,31 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
53405321
The Colormap instance or registered colormap name used to map
53415322
scalar data to colors. This parameter is ignored for RGB(A) data.
53425323
5343-
norm : `~matplotlib.colors.Normalize`, optional
5344-
The `.Normalize` instance used to scale scalar data to the [0, 1]
5324+
norm : str or `~matplotlib.colors.Normalize`, optional
5325+
The normalization method used to scale scalar data to the [0, 1]
53455326
range before mapping to colors using *cmap*. By default, a linear
53465327
scaling mapping the lowest value to 0 and the highest to 1 is used.
53475328
This parameter is ignored for RGB(A) data.
53485329
5330+
If given, this can be one of the following:
5331+
5332+
- An instance of `.Normalize` or one of its subclasses
5333+
(see :doc:`/tutorials/colors/colormapnorms`).
5334+
- A scale name, i.e. one of "linear", "log", "symlog", "logit",
5335+
etc. For a full list of available scales call
5336+
`matplotlib.scales.get_scale_names()`.
5337+
In that case, a suitable `.Normalize` subclass is dynamically
5338+
generated and instantiated.
5339+
5340+
vmin, vmax : float, optional
5341+
When using scalar data and no explicit *norm*, *vmin* and *vmax*
5342+
define the data range that the colormap covers. By default, the
5343+
colormap covers the complete value range of the supplied data. It
5344+
is an error to use *vmin*/*vmax* when a *norm* instance is given
5345+
(but using a `str` *norm* name together with *vmin*/*vmax* is
5346+
acceptable). When using RGB(A) data, parameters *vmin*/*vmax* are
5347+
ignored.
5348+
53495349
aspect : {'equal', 'auto'} or float, default: :rc:`image.aspect`
53505350
The aspect ratio of the Axes. This parameter is particularly
53515351
relevant for images since it determines whether data pixels are
@@ -5404,13 +5404,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54045404
If *alpha* is an array, the alpha blending values are applied pixel
54055405
by pixel, and *alpha* must have the same shape as *X*.
54065406
5407-
vmin, vmax : float, optional
5408-
When using scalar data and no explicit *norm*, *vmin* and *vmax*
5409-
define the data range that the colormap covers. By default,
5410-
the colormap covers the complete value range of the supplied
5411-
data. It is an error to use *vmin*/*vmax* when *norm* is given.
5412-
When using RGB(A) data, parameters *vmin*/*vmax* are ignored.
5413-
54145407
origin : {'upper', 'lower'}, default: :rc:`image.origin`
54155408
Place the [0, 0] index of the array in the upper left or lower
54165409
left corner of the Axes. The convention (the default) 'upper' is
@@ -5721,21 +5714,9 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
57215714
See :doc:`/gallery/images_contours_and_fields/pcolormesh_grids`
57225715
for more description.
57235716
5724-
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
5725-
A Colormap instance or registered colormap name. The colormap
5726-
maps the *C* values to colors.
5727-
5728-
norm : `~matplotlib.colors.Normalize`, optional
5729-
The Normalize instance scales the data values to the canonical
5730-
colormap range [0, 1] for mapping to colors. By default, the data
5731-
range is mapped to the colorbar range using linear scaling.
5732-
5733-
vmin, vmax : float, default: None
5734-
The colorbar range. If *None*, suitable min/max values are
5735-
automatically chosen by the `.Normalize` instance (defaults to
5736-
the respective min/max values of *C* in case of the default linear
5737-
scaling).
5738-
It is an error to use *vmin*/*vmax* when *norm* is given.
5717+
cmap, norm, vmin, vmax
5718+
Data normalization and colormapping parameters for *C*. See
5719+
`~.Axes.imshow` for a detailed description.
57395720
57405721
edgecolors : {'none', None, 'face', color, color sequence}, optional
57415722
The color of the edges. Defaults to 'none'. Possible values:
@@ -5947,21 +5928,9 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
59475928
expanded as needed into the appropriate 2D arrays, making a
59485929
rectangular grid.
59495930
5950-
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
5951-
A Colormap instance or registered colormap name. The colormap
5952-
maps the *C* values to colors.
5953-
5954-
norm : `~matplotlib.colors.Normalize`, optional
5955-
The Normalize instance scales the data values to the canonical
5956-
colormap range [0, 1] for mapping to colors. By default, the data
5957-
range is mapped to the colorbar range using linear scaling.
5958-
5959-
vmin, vmax : float, default: None
5960-
The colorbar range. If *None*, suitable min/max values are
5961-
automatically chosen by the `.Normalize` instance (defaults to
5962-
the respective min/max values of *C* in case of the default linear
5963-
scaling).
5964-
It is an error to use *vmin*/*vmax* when *norm* is given.
5931+
cmap, norm, vmin, vmax
5932+
Data normalization and colormapping parameters for *C*. See
5933+
`~.Axes.imshow` for a detailed description.
59655934
59665935
edgecolors : {'none', None, 'face', color, color sequence}, optional
59675936
The color of the edges. Defaults to 'none'. Possible values:
@@ -6195,21 +6164,9 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61956164
61966165
These arguments can only be passed positionally.
61976166
6198-
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
6199-
A Colormap instance or registered colormap name. The colormap
6200-
maps the *C* values to colors.
6201-
6202-
norm : `~matplotlib.colors.Normalize`, optional
6203-
The Normalize instance scales the data values to the canonical
6204-
colormap range [0, 1] for mapping to colors. By default, the data
6205-
range is mapped to the colorbar range using linear scaling.
6206-
6207-
vmin, vmax : float, default: None
6208-
The colorbar range. If *None*, suitable min/max values are
6209-
automatically chosen by the `.Normalize` instance (defaults to
6210-
the respective min/max values of *C* in case of the default linear
6211-
scaling).
6212-
It is an error to use *vmin*/*vmax* when *norm* is given.
6167+
cmap, norm, vmin, vmax
6168+
Data normalization and colormapping parameters for *C*. See
6169+
`~.Axes.imshow` for a detailed description.
62136170
62146171
alpha : float, default: None
62156172
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -6964,16 +6921,9 @@ def hist2d(self, x, y, bins=10, range=None, density=False, weights=None,
69646921
69656922
Other Parameters
69666923
----------------
6967-
cmap : Colormap or str, optional
6968-
A `.colors.Colormap` instance. If not set, use rc settings.
6969-
6970-
norm : Normalize, optional
6971-
A `.colors.Normalize` instance is used to
6972-
scale luminance data to ``[0, 1]``. If not set, defaults to
6973-
`.colors.Normalize()`.
6974-
6975-
vmin/vmax : None or scalar, optional
6976-
Arguments passed to the `~.colors.Normalize` instance.
6924+
cmap, norm, vmin, vmax
6925+
Data normalization and colormapping parameters. See `~.Axes.imshow`
6926+
for a detailed description.
69776927
69786928
alpha : ``0 <= scalar <= 1`` or ``None``, optional
69796929
The alpha blending value.

lib/matplotlib/collections.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,9 @@ def __init__(self,
131131
offset_transform : `~.Transform`, default: `.IdentityTransform`
132132
A single transform which will be applied to each *offsets* vector
133133
before it is used.
134-
norm : `~.colors.Normalize`, optional
135-
Forwarded to `.ScalarMappable`. The default of
136-
``None`` means that the first draw call will set ``vmin`` and
137-
``vmax`` using the minimum and maximum values of the data.
138-
cmap : `~.colors.Colormap`, optional
139-
Forwarded to `.ScalarMappable`. The default of
140-
``None`` will result in :rc:`image.cmap` being used.
134+
cmap, norm
135+
Data normalization and colormapping parameters. See
136+
`.ScalarMappable` for a detailed description.
141137
hatch : str, optional
142138
Hatching pattern to use in filled paths, if any. Valid strings are
143139
['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']. See

lib/matplotlib/contour.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,21 +1635,14 @@ def _initialize_x_y(self, z):
16351635
alpha : float, default: 1
16361636
The alpha blending value, between 0 (transparent) and 1 (opaque).
16371637
1638-
cmap : str or `.Colormap`, default: :rc:`image.cmap`
1639-
A `.Colormap` instance or registered colormap name. The colormap
1640-
maps the level values to colors.
1638+
cmap, norm, vmin, vmax
1639+
Data normalization and colormapping parameters for *Z*. See `~.Axes.imshow`
1640+
for a detailed description.
16411641
1642-
If both *colors* and *cmap* are given, an error is raised.
1642+
*cmap* cannot be given together with *colors*.
16431643
1644-
norm : `~matplotlib.colors.Normalize`, optional
1645-
If a colormap is used, the `.Normalize` instance scales the level
1646-
values to the canonical colormap range [0, 1] for mapping to
1647-
colors. If not given, the default linear scaling is used.
1648-
1649-
vmin, vmax : float, optional
1650-
If not *None*, either or both of these values will be supplied to
1651-
the `.Normalize` instance, overriding the default color scaling
1652-
based on *levels*.
1644+
If *vmin* or *vmax* are not given, the default color scaling is based on
1645+
*levels*.
16531646
16541647
origin : {*None*, 'upper', 'lower', 'image'}, default: None
16551648
Determines the orientation and exact position of *Z* by specifying

lib/matplotlib/figure.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,16 +2747,9 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
27472747
alpha : None or float
27482748
The alpha blending value.
27492749
2750-
norm : `matplotlib.colors.Normalize`
2751-
A `.Normalize` instance to map the luminance to the
2752-
interval [0, 1].
2753-
2754-
cmap : str or `matplotlib.colors.Colormap`, default: :rc:`image.cmap`
2755-
The colormap to use.
2756-
2757-
vmin, vmax : float
2758-
If *norm* is not given, these values set the data limits for the
2759-
colormap.
2750+
cmap, norm, vmin, vmax
2751+
Data normalization and colormapping parameters for *X*. See
2752+
`~.Axes.imshow` for a detailed description.
27602753
27612754
origin : {'upper', 'lower'}, default: :rc:`image.origin`
27622755
Indicates where the [0, 0] index of the array is in the upper left

lib/matplotlib/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ class AxesImage(_ImageBase):
865865
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
866866
The Colormap instance or registered colormap name used to map scalar
867867
data to colors.
868-
norm : `~matplotlib.colors.Normalize`
868+
norm : str or `~matplotlib.colors.Normalize`
869869
Maps luminance to 0-1.
870870
interpolation : str, default: :rc:`image.interpolation`
871871
Supported values are 'none', 'antialiased', 'nearest', 'bilinear',
@@ -1216,7 +1216,7 @@ def __init__(self, ax,
12161216
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
12171217
The Colormap instance or registered colormap name used to map
12181218
scalar data to colors.
1219-
norm : `~matplotlib.colors.Normalize`
1219+
norm : str or `~matplotlib.colors.Normalize`
12201220
Maps luminance to 0-1.
12211221
**kwargs : `.Artist` properties
12221222
"""

lib/matplotlib/streamplot.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
4646
The streamline color. If given an array, its values are converted to
4747
colors using *cmap* and *norm*. The array must have the same shape
4848
as *u* and *v*.
49-
cmap : `~matplotlib.colors.Colormap`
50-
Colormap used to plot streamlines and arrows. This is only used if
51-
*color* is an array.
52-
norm : `~matplotlib.colors.Normalize`
53-
Normalize object used to scale luminance data to 0, 1. If ``None``,
54-
stretch (min, max) to (0, 1). This is only used if *color* is an array.
49+
cmap, norm
50+
Data normalization and colormapping parameters for *color*; only used
51+
if *color* is an array of floats. See `~.Axes.imshow` for a detailed
52+
description.
5553
arrowsize : float
5654
Scaling factor for the arrow size.
5755
arrowstyle : str

lib/matplotlib/tri/tricontour.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,14 @@ def _contour_args(self, args, kwargs):
143143
alpha : float, default: 1
144144
The alpha blending value, between 0 (transparent) and 1 (opaque).
145145
146-
cmap : str or `.Colormap`, default: :rc:`image.cmap`
147-
A `.Colormap` instance or registered colormap name. The colormap maps the
148-
level values to colors.
146+
cmap, norm, vmin, vmax
147+
Data normalization and colormapping parameters for *Z*. See `~.Axes.imshow`
148+
for a detailed description.
149149
150-
If both *colors* and *cmap* are given, an error is raised.
150+
*cmap* cannot be given together with *colors*.
151151
152-
norm : `~matplotlib.colors.Normalize`, optional
153-
If a colormap is used, the `.Normalize` instance scales the level values to
154-
the canonical colormap range [0, 1] for mapping to colors. If not given,
155-
the default linear scaling is used.
156-
157-
vmin, vmax : float, optional
158-
If not *None*, either or both of these values will be supplied to
159-
the `.Normalize` instance, overriding the default color scaling
160-
based on *levels*.
152+
If *vmin* or *vmax* are not given, the default color scaling is based on
153+
*levels*.
161154
162155
origin : {*None*, 'upper', 'lower', 'image'}, default: None
163156
Determines the orientation and exact position of *Z* by specifying the

0 commit comments

Comments
 (0)