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

Skip to content

Commit 48eb32b

Browse files
committed
docstrings for multivariate plotting in imshow, pcolor and pcolormesh
1 parent 1ea7e31 commit 48eb32b

4 files changed

Lines changed: 65 additions & 24 deletions

File tree

doc/api/colors_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Multivariate Colormaps
5353
BivarColormap
5454
SegmentedBivarColormap
5555
BivarColormapFromImage
56+
MultivarColormap
5657

5758
Other classes
5859
-------------

lib/matplotlib/axes/_axes.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5753,7 +5753,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57535753
"""
57545754
Display data as an image, i.e., on a 2D regular raster.
57555755
5756-
The input may either be actual RGB(A) data, or 2D scalar data, which
5756+
The input may either be actual RGB(A) data, or 2D data, which
57575757
will be rendered as a pseudocolor image. For displaying a grayscale
57585758
image, set up the colormapping using the parameters
57595759
``cmap='gray', vmin=0, vmax=255``.
@@ -5774,24 +5774,25 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57745774
- (M, N): an image with scalar data. The values are mapped to
57755775
colors using normalization and a colormap. See parameters *norm*,
57765776
*cmap*, *vmin*, *vmax*.
5777+
- (K, M, N): multiple images with scalar data. Must be used
5778+
with a multivariate or bivariate colormap. See *cmap*.
57775779
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
57785780
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
57795781
i.e. including transparency.
57805782
5781-
The first two dimensions (M, N) define the rows and columns of
5782-
the image.
5783+
Here M and N define the rows and columns of the image.
57835784
57845785
Out-of-range RGB(A) values are clipped.
57855786
5786-
%(cmap_doc)s
5787+
%(multi_cmap_doc)s
57875788
57885789
This parameter is ignored if *X* is RGB(A).
57895790
5790-
%(norm_doc)s
5791+
%(multi_norm_doc)s
57915792
57925793
This parameter is ignored if *X* is RGB(A).
57935794
5794-
%(vmin_vmax_doc)s
5795+
%(multi_vmin_vmax_doc)s
57955796
57965797
This parameter is ignored if *X* is RGB(A).
57975798
@@ -6130,9 +6131,10 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
61306131
61316132
Parameters
61326133
----------
6133-
C : 2D array-like
6134+
C : 2D array-like or list of 2D array-like objects
61346135
The color-mapped values. Color-mapping is controlled by *cmap*,
6135-
*norm*, *vmin*, and *vmax*.
6136+
*norm*, *vmin*, and *vmax*. Multiple arrays are only supported
6137+
when a bivariate or mulivariate colormap is used, see *cmap*.
61366138
61376139
X, Y : array-like, optional
61386140
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -6179,11 +6181,11 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
61796181
See :doc:`/gallery/images_contours_and_fields/pcolormesh_grids`
61806182
for more description.
61816183
6182-
%(cmap_doc)s
6184+
%(multi_cmap_doc)s
61836185
6184-
%(norm_doc)s
6186+
%(multi_norm_doc)s
61856187
6186-
%(vmin_vmax_doc)s
6188+
%(multi_vmin_vmax_doc)s
61876189
61886190
%(colorizer_doc)s
61896191
@@ -6370,12 +6372,13 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63706372
- (M, N) or M*N: a mesh with scalar data. The values are mapped to
63716373
colors using normalization and a colormap. See parameters *norm*,
63726374
*cmap*, *vmin*, *vmax*.
6375+
- (K, M, N): multiple images with scalar data. Must be used with
6376+
a multivariate or bivariate colormap. See *cmap*.
63736377
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
63746378
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
63756379
i.e. including transparency.
63766380
6377-
The first two dimensions (M, N) define the rows and columns of
6378-
the mesh data.
6381+
Here M and N define the rows and columns of the image.
63796382
63806383
X, Y : array-like, optional
63816384
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -6406,11 +6409,11 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
64066409
expanded as needed into the appropriate 2D arrays, making a
64076410
rectangular grid.
64086411
6409-
%(cmap_doc)s
6412+
%(multi_cmap_doc)s
64106413
6411-
%(norm_doc)s
6414+
%(multi_norm_doc)s
64126415
6413-
%(vmin_vmax_doc)s
6416+
%(multi_vmin_vmax_doc)s
64146417
64156418
%(colorizer_doc)s
64166419

lib/matplotlib/colorizer.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,15 @@ def _get_colorizer(cmap, norm, colorizer):
607607
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
608608
The Colormap instance or registered colormap name used to map scalar data
609609
to colors.""",
610+
multi_cmap_doc="""\
611+
cmap : str, `~matplotlib.colors.Colormap`, `~matplotlib.colors.BivarColormap`\
612+
or `~matplotlib.colors.MultivarColormap`, default: :rc:`image.cmap`
613+
The Colormap instance or registered colormap name used to map
614+
scalar/multivariate data to colors.
615+
616+
Multivariate data is only accepted if a multivariate colormap
617+
(`~matplotlib.colors.BivarColormap` or `~matplotlib.colors.MultivarColormap`)
618+
is used.""",
610619
norm_doc="""\
611620
norm : str or `~matplotlib.colors.Normalize`, optional
612621
The normalization method used to scale scalar data to the [0, 1] range
@@ -621,13 +630,41 @@ def _get_colorizer(cmap, norm, colorizer):
621630
list of available scales, call `matplotlib.scale.get_scale_names()`.
622631
In that case, a suitable `.Normalize` subclass is dynamically generated
623632
and instantiated.""",
633+
multi_norm_doc="""\
634+
norm : str, `~matplotlib.colors.Normalize` or list, optional
635+
The normalization method used to scale data to the [0, 1] range
636+
before mapping to colors using *cmap*. By default, a linear scaling is
637+
used, mapping the lowest value to 0 and the highest to 1.
638+
639+
If given, this can be one of the following:
640+
641+
- An instance of `.Normalize` or one of its subclasses
642+
(see :ref:`colormapnorms`).
643+
- A scale name, i.e. one of "linear", "log", "symlog", "logit", etc. For a
644+
list of available scales, call `matplotlib.scale.get_scale_names()`.
645+
In that case, a suitable `.Normalize` subclass is dynamically generated
646+
and instantiated.
647+
- A list of scale names or `.Normalize` objects matching the number of
648+
variates in the colormap, for use with `~matplotlib.colors.BivarColormap`
649+
or `~matplotlib.colors.MultivarColormap`, i.e. ``["linear", "log"]``.""",
624650
vmin_vmax_doc="""\
625651
vmin, vmax : float, optional
626652
When using scalar data and no explicit *norm*, *vmin* and *vmax* define
627653
the data range that the colormap covers. By default, the colormap covers
628654
the complete value range of the supplied data. It is an error to use
629655
*vmin*/*vmax* when a *norm* instance is given (but using a `str` *norm*
630656
name together with *vmin*/*vmax* is acceptable).""",
657+
multi_vmin_vmax_doc="""\
658+
vmin, vmax : float or list, optional
659+
When using scalar data and no explicit *norm*, *vmin* and *vmax* define
660+
the data range that the colormap covers. By default, the colormap covers
661+
the complete value range of the supplied data. It is an error to use
662+
*vmin*/*vmax* when a *norm* instance is given (but using a `str` *norm*
663+
name together with *vmin*/*vmax* is acceptable).
664+
665+
A list can be used to define independent limits for each variate when
666+
using a `~matplotlib.colors.BivarColormap` or
667+
`~matplotlib.colors.MultivarColormap`.""",
631668
)
632669

633670

lib/matplotlib/colors.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,10 +1420,10 @@ def __init__(self, colormaps, combination_mode, name='multivariate colormap'):
14201420
combination_mode: str, 'sRGB_add' or 'sRGB_sub'
14211421
Describe how colormaps are combined in sRGB space
14221422
1423-
- If 'sRGB_add' -> Mixing produces brighter colors
1424-
`sRGB = sum(colors)`
1425-
- If 'sRGB_sub' -> Mixing produces darker colors
1426-
`sRGB = 1 - sum(1 - colors)`
1423+
- If 'sRGB_add': Mixing produces brighter colors
1424+
``sRGB = sum(colors)``
1425+
- If 'sRGB_sub': Mixing produces darker colors
1426+
``sRGB = 1 - sum(1 - colors)``
14271427
name : str, optional
14281428
The name of the colormap family.
14291429
"""
@@ -1598,12 +1598,12 @@ def with_extremes(self, *, bad=None, under=None, over=None):
15981598
bad: :mpltype:`color`, default: None
15991599
If Matplotlib color, the bad value is set accordingly in the copy
16001600
1601-
under tuple of :mpltype:`color`, default: None
1602-
If tuple, the `under` value of each component is set with the values
1601+
under: tuple of :mpltype:`color`, default: None
1602+
If tuple, the ``under`` value of each component is set with the values
16031603
from the tuple.
16041604
1605-
over tuple of :mpltype:`color`, default: None
1606-
If tuple, the `over` value of each component is set with the values
1605+
over: tuple of :mpltype:`color`, default: None
1606+
If tuple, the ``over`` value of each component is set with the values
16071607
from the tuple.
16081608
16091609
Returns

0 commit comments

Comments
 (0)