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

Skip to content

Commit c6772c0

Browse files
committed
Use docstring interpolation instead.
1 parent 7b34dc1 commit c6772c0

File tree

5 files changed

+106
-75
lines changed

5 files changed

+106
-75
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,6 +4323,7 @@ def invalid_shape_exception(csize, xsize):
43234323
"edgecolors", "c", "facecolor",
43244324
"facecolors", "color"],
43254325
label_namer="y")
4326+
@_docstring.interpd
43264327
def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43274328
vmin=None, vmax=None, alpha=None, linewidths=None, *,
43284329
edgecolors=None, plotnonfinite=False, **kwargs):
@@ -4369,10 +4370,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43694370
See :mod:`matplotlib.markers` for more information about marker
43704371
styles.
43714372
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.
4373+
%(cmap_doc)s
4374+
4375+
%(norm_doc)s
4376+
4377+
%(vmin_vmax_doc)s
43764378
43774379
alpha : float, default: None
43784380
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -4645,9 +4647,11 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
46454647
46464648
Other Parameters
46474649
----------------
4648-
cmap, norm, vmin, vmax
4649-
Data normalization and colormapping parameters. See `~.Axes.imshow`
4650-
for a detailed description.
4650+
%(cmap_doc)s
4651+
4652+
%(norm_doc)s
4653+
4654+
%(vmin_vmax_doc)s
46514655
46524656
alpha : float between 0 and 1, optional
46534657
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -5279,6 +5283,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
52795283
# the documentation for *norm*, *vmax* and *vmin* together.
52805284
@_api.make_keyword_only("3.5", "aspect")
52815285
@_preprocess_data()
5286+
@_docstring.interpd
52825287
def imshow(self, X, cmap=None, norm=None, aspect=None,
52835288
interpolation=None, alpha=None,
52845289
vmin=None, vmax=None, origin=None, extent=None, *,
@@ -5317,34 +5322,11 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
53175322
53185323
Out-of-range RGB(A) values are clipped.
53195324
5320-
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
5321-
The Colormap instance or registered colormap name used to map
5322-
scalar data to colors. This parameter is ignored for RGB(A) data.
5323-
5324-
norm : str or `~matplotlib.colors.Normalize`, optional
5325-
The normalization method used to scale scalar data to the [0, 1]
5326-
range before mapping to colors using *cmap*. By default, a linear
5327-
scaling mapping the lowest value to 0 and the highest to 1 is used.
5328-
This parameter is ignored for RGB(A) data.
5329-
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.
5325+
%(cmap_doc)s
5326+
5327+
%(norm_doc)s
5328+
5329+
%(vmin_vmax_doc)s
53485330
53495331
aspect : {'equal', 'auto'} or float, default: :rc:`image.aspect`
53505332
The aspect ratio of the Axes. This parameter is particularly
@@ -5667,7 +5649,8 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
56675649
Parameters
56685650
----------
56695651
C : 2D array-like
5670-
The color-mapped values.
5652+
The color-mapped values. Color-mapping is controlled by *cmap*,
5653+
*norm*, *vmin*, and *vmax*.
56715654
56725655
X, Y : array-like, optional
56735656
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -5714,9 +5697,11 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
57145697
See :doc:`/gallery/images_contours_and_fields/pcolormesh_grids`
57155698
for more description.
57165699
5717-
cmap, norm, vmin, vmax
5718-
Data normalization and colormapping parameters for *C*. See
5719-
`~.Axes.imshow` for a detailed description.
5700+
%(cmap_doc)s
5701+
5702+
%(norm_doc)s
5703+
5704+
%(vmin_vmax_doc)s
57205705
57215706
edgecolors : {'none', None, 'face', color, color sequence}, optional
57225707
The color of the edges. Defaults to 'none'. Possible values:
@@ -5897,7 +5882,8 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
58975882
Parameters
58985883
----------
58995884
C : 2D array-like
5900-
The color-mapped values.
5885+
The color-mapped values. Color-mapping is controlled by *cmap*,
5886+
*norm*, *vmin*, and *vmax*.
59015887
59025888
X, Y : array-like, optional
59035889
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -5928,9 +5914,11 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
59285914
expanded as needed into the appropriate 2D arrays, making a
59295915
rectangular grid.
59305916
5931-
cmap, norm, vmin, vmax
5932-
Data normalization and colormapping parameters for *C*. See
5933-
`~.Axes.imshow` for a detailed description.
5917+
%(cmap_doc)s
5918+
5919+
%(norm_doc)s
5920+
5921+
%(vmin_vmax_doc)s
59345922
59355923
edgecolors : {'none', None, 'face', color, color sequence}, optional
59365924
The color of the edges. Defaults to 'none'. Possible values:
@@ -6120,8 +6108,8 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61206108
C : array-like
61216109
The image data. Supported array shapes are:
61226110
6123-
- (M, N): an image with scalar data. The data is visualized
6124-
using a colormap.
6111+
- (M, N): an image with scalar data. Color-mapping is controlled
6112+
by *cmap*, *norm*, *vmin*, and *vmax*.
61256113
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
61266114
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
61276115
i.e. including transparency.
@@ -6164,9 +6152,11 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61646152
61656153
These arguments can only be passed positionally.
61666154
6167-
cmap, norm, vmin, vmax
6168-
Data normalization and colormapping parameters for *C*. See
6169-
`~.Axes.imshow` for a detailed description.
6155+
%(cmap_doc)s
6156+
6157+
%(norm_doc)s
6158+
6159+
%(vmin_vmax_doc)s
61706160
61716161
alpha : float, default: None
61726162
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -6921,9 +6911,11 @@ def hist2d(self, x, y, bins=10, range=None, density=False, weights=None,
69216911
69226912
Other Parameters
69236913
----------------
6924-
cmap, norm, vmin, vmax
6925-
Data normalization and colormapping parameters. See `~.Axes.imshow`
6926-
for a detailed description.
6914+
%(cmap_doc)s
6915+
6916+
%(norm_doc)s
6917+
6918+
%(vmin_vmax_doc)s
69276919
69286920
alpha : ``0 <= scalar <= 1`` or ``None``, optional
69296921
The alpha blending value.

lib/matplotlib/cm.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,35 @@ def changed(self):
633633
"""
634634
self.callbacks.process('changed', self)
635635
self.stale = True
636+
637+
638+
# The docstrings here must be generic enough to apply to all relevant methods.
639+
mpl._docstring.interpd.update(
640+
cmap_doc="""\
641+
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
642+
The Colormap instance or registered colormap name used to map scalar data
643+
to colors. This parameter is ignored for RGB(A) data.""",
644+
norm_doc="""\
645+
norm : str or `~matplotlib.colors.Normalize`, optional
646+
The normalization method used to scale scalar data to the [0, 1] range
647+
before mapping to colors using *cmap*. By default, a linear scaling is
648+
used, mapping the lowest value to 0 and the highest to 1. This parameter is
649+
ignored for RGB(A) data.
650+
651+
If given, this can be one of the following:
652+
653+
- An instance of `.Normalize` or one of its subclasses
654+
(see :doc:`/tutorials/colors/colormapnorms`).
655+
- A scale name, i.e. one of "linear", "log", "symlog", "logit", etc. For a
656+
list of available scales, call `matplotlib.scale.get_scale_names()`.
657+
In that case, a suitable `.Normalize` subclass is dynamically generated
658+
and instantiated.""",
659+
vmin_vmax_doc="""\
660+
vmin, vmax : float, optional
661+
When using scalar data and no explicit *norm*, *vmin* and *vmax* define
662+
the data range that the colormap covers. By default, the colormap covers
663+
the complete value range of the supplied data. It is an error to use
664+
*vmin*/*vmax* when a *norm* instance is given (but using a `str` *norm*
665+
name together with *vmin*/*vmax* is acceptable). When using RGB(A) data,
666+
parameters *vmin*/*vmax* are ignored.""",
667+
)

lib/matplotlib/contour.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,8 @@ def _initialize_x_y(self, z):
15921592
``X = range(N)``, ``Y = range(M)``.
15931593
15941594
Z : (M, N) array-like
1595-
The height values over which the contour is drawn.
1595+
The height values over which the contour is drawn. Color-mapping is
1596+
controlled by *cmap*, *norm*, *vmin*, and *vmax*.
15961597
15971598
levels : int or array-like, optional
15981599
Determines the number and positions of the contour lines / regions.
@@ -1635,11 +1636,11 @@ def _initialize_x_y(self, z):
16351636
alpha : float, default: 1
16361637
The alpha blending value, between 0 (transparent) and 1 (opaque).
16371638
1638-
cmap, norm, vmin, vmax
1639-
Data normalization and colormapping parameters for *Z*. See `~.Axes.imshow`
1640-
for a detailed description.
1639+
%(cmap_doc)s
16411640
1642-
*cmap* cannot be given together with *colors*.
1641+
%(norm_doc)s
1642+
1643+
%(vmin_vmax_doc)s
16431644
16441645
If *vmin* or *vmax* are not given, the default color scaling is based on
16451646
*levels*.
@@ -1798,4 +1799,4 @@ def _initialize_x_y(self, z):
17981799
<https://en.wikipedia.org/wiki/Marching_squares>`_ algorithm to
17991800
compute contour locations. More information can be found in
18001801
`ContourPy documentation <https://contourpy.readthedocs.io>`_.
1801-
""")
1802+
""" % _docstring.interpd.params)

lib/matplotlib/figure.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,7 @@ def set_canvas(self, canvas):
27242724
"""
27252725
self.canvas = canvas
27262726

2727+
@_docstring.interpd
27272728
def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
27282729
vmin=None, vmax=None, origin=None, resize=False, **kwargs):
27292730
"""
@@ -2737,19 +2738,23 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
27372738
X
27382739
The image data. This is an array of one of the following shapes:
27392740
2740-
- MxN: luminance (grayscale) values
2741-
- MxNx3: RGB values
2742-
- MxNx4: RGBA values
2741+
- (M, N): an image with scalar data. Color-mapping is controlled
2742+
by *cmap*, *norm*, *vmin*, and *vmax*.
2743+
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
2744+
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
2745+
i.e. including transparency.
27432746
27442747
xo, yo : int
27452748
The *x*/*y* image offset in pixels.
27462749
27472750
alpha : None or float
27482751
The alpha blending value.
27492752
2750-
cmap, norm, vmin, vmax
2751-
Data normalization and colormapping parameters for *X*. See
2752-
`~.Axes.imshow` for a detailed description.
2753+
%(cmap_doc)s
2754+
2755+
%(norm_doc)s
2756+
2757+
%(vmin_vmax_doc)s
27532758
27542759
origin : {'upper', 'lower'}, default: :rc:`image.origin`
27552760
Indicates where the [0, 0] index of the array is in the upper left

lib/matplotlib/tri/tricontour.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ def _contour_args(self, args, kwargs):
8282

8383

8484
_docstring.interpd.update(_tricontour_doc="""
85-
Draw contour %(type)s on an unstructured triangular grid.
85+
Draw contour %%(type)s on an unstructured triangular grid.
8686
8787
Call signatures::
8888
89-
%(func)s(triangulation, Z, [levels], ...)
90-
%(func)s(x, y, Z, [levels], *, [triangles=triangles], [mask=mask], ...)
89+
%%(func)s(triangulation, Z, [levels], ...)
90+
%%(func)s(x, y, Z, [levels], *, [triangles=triangles], [mask=mask], ...)
9191
9292
The triangular grid can be specified either by passing a `.Triangulation`
9393
object as the first parameter, or by passing the points *x*, *y* and
@@ -96,7 +96,7 @@ def _contour_args(self, args, kwargs):
9696
*triangles* are given, the triangulation is calculated on the fly.
9797
9898
It is possible to pass *triangles* positionally, i.e.
99-
``%(func)s(x, y, triangles, Z, ...)``. However, this is discouraged. For more
99+
``%%(func)s(x, y, triangles, Z, ...)``. However, this is discouraged. For more
100100
clarity, pass *triangles* via keyword argument.
101101
102102
Parameters
@@ -109,7 +109,8 @@ def _contour_args(self, args, kwargs):
109109
This is mutually exclusive with specifying *triangulation*.
110110
111111
Z : array-like
112-
The height values over which the contour is drawn.
112+
The height values over which the contour is drawn. Color-mapping is
113+
controlled by *cmap*, *norm*, *vmin*, and *vmax*.
113114
114115
levels : int or array-like, optional
115116
Determines the number and positions of the contour lines / regions.
@@ -128,7 +129,7 @@ def _contour_args(self, args, kwargs):
128129
Other Parameters
129130
----------------
130131
colors : color string or sequence of colors, optional
131-
The colors of the levels, i.e., the contour %(type)s.
132+
The colors of the levels, i.e., the contour %%(type)s.
132133
133134
The sequence is cycled for the levels in ascending order. If the sequence
134135
is shorter than the number of levels, it's repeated.
@@ -143,11 +144,11 @@ def _contour_args(self, args, kwargs):
143144
alpha : float, default: 1
144145
The alpha blending value, between 0 (transparent) and 1 (opaque).
145146
146-
cmap, norm, vmin, vmax
147-
Data normalization and colormapping parameters for *Z*. See `~.Axes.imshow`
148-
for a detailed description.
147+
%(cmap_doc)s
149148
150-
*cmap* cannot be given together with *colors*.
149+
%(norm_doc)s
150+
151+
%(vmin_vmax_doc)s
151152
152153
If *vmin* or *vmax* are not given, the default color scaling is based on
153154
*levels*.
@@ -177,7 +178,7 @@ def _contour_args(self, args, kwargs):
177178
Defaults to `~.ticker.MaxNLocator`.
178179
179180
extend : {'neither', 'both', 'min', 'max'}, default: 'neither'
180-
Determines the ``%(func)s``-coloring of values that are outside the
181+
Determines the ``%%(func)s``-coloring of values that are outside the
181182
*levels* range.
182183
183184
If 'neither', values outside the *levels* range are not colored. If 'min',
@@ -205,7 +206,7 @@ def _contour_args(self, args, kwargs):
205206
antialiased : bool, optional
206207
Enable antialiasing, overriding the defaults. For
207208
filled contours, the default is *True*. For line contours,
208-
it is taken from :rc:`lines.antialiased`.""")
209+
it is taken from :rc:`lines.antialiased`.""" % _docstring.interpd.params)
209210

210211

211212
@_docstring.Substitution(func='tricontour', type='lines')

0 commit comments

Comments
 (0)