Use docstring interpolation instead. · matplotlib/matplotlib@c6772c0 · GitHub
Skip to content

Commit c6772c0

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

5 files changed

Lines changed: 106 additions & 75 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 43 additions & 51 deletions

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

0 commit comments

Comments
 (0)