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

Skip to content

Commit 5afd692

Browse files
committed
docstrings for multivariate plotting in imshow, pcolor and pcolormesh
1 parent e708a2b commit 5afd692

3 files changed

Lines changed: 57 additions & 16 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
@@ -5714,7 +5714,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57145714
"""
57155715
Display data as an image, i.e., on a 2D regular raster.
57165716
5717-
The input may either be actual RGB(A) data, or 2D scalar data, which
5717+
The input may either be actual RGB(A) data, or 2D data, which
57185718
will be rendered as a pseudocolor image. For displaying a grayscale
57195719
image, set up the colormapping using the parameters
57205720
``cmap='gray', vmin=0, vmax=255``.
@@ -5735,24 +5735,25 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57355735
- (M, N): an image with scalar data. The values are mapped to
57365736
colors using normalization and a colormap. See parameters *norm*,
57375737
*cmap*, *vmin*, *vmax*.
5738+
- (K, M, N): multiple images with scalar data. Must be used
5739+
with a multivariate or bivariate colormap. See *cmap*.
57385740
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
57395741
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
57405742
i.e. including transparency.
57415743
5742-
The first two dimensions (M, N) define the rows and columns of
5743-
the image.
5744+
Here M and N define the rows and columns of the image.
57445745
57455746
Out-of-range RGB(A) values are clipped.
57465747
5747-
%(cmap_doc)s
5748+
%(multi_cmap_doc)s
57485749
57495750
This parameter is ignored if *X* is RGB(A).
57505751
5751-
%(norm_doc)s
5752+
%(multi_norm_doc)s
57525753
57535754
This parameter is ignored if *X* is RGB(A).
57545755
5755-
%(vmin_vmax_doc)s
5756+
%(multi_vmin_vmax_doc)s
57565757
57575758
This parameter is ignored if *X* is RGB(A).
57585759
@@ -6087,9 +6088,10 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
60876088
60886089
Parameters
60896090
----------
6090-
C : 2D array-like
6091+
C : 2D array-like or list of 2D array-like objects
60916092
The color-mapped values. Color-mapping is controlled by *cmap*,
6092-
*norm*, *vmin*, and *vmax*.
6093+
*norm*, *vmin*, and *vmax*. Multiple arrays are only supported
6094+
when a bivariate or mulivariate colormap is used, see *cmap*.
60936095
60946096
X, Y : array-like, optional
60956097
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -6136,11 +6138,11 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
61366138
See :doc:`/gallery/images_contours_and_fields/pcolormesh_grids`
61376139
for more description.
61386140
6139-
%(cmap_doc)s
6141+
%(multi_cmap_doc)s
61406142
6141-
%(norm_doc)s
6143+
%(multi_norm_doc)s
61426144
6143-
%(vmin_vmax_doc)s
6145+
%(multi_vmin_vmax_doc)s
61446146
61456147
%(colorizer_doc)s
61466148
@@ -6327,12 +6329,13 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63276329
- (M, N) or M*N: a mesh with scalar data. The values are mapped to
63286330
colors using normalization and a colormap. See parameters *norm*,
63296331
*cmap*, *vmin*, *vmax*.
6332+
- (K, M, N): multiple images with scalar data. Must be used with
6333+
a multivariate or bivariate colormap. See *cmap*.
63306334
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
63316335
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
63326336
i.e. including transparency.
63336337
6334-
The first two dimensions (M, N) define the rows and columns of
6335-
the mesh data.
6338+
Here M and N define the rows and columns of the image.
63366339
63376340
X, Y : array-like, optional
63386341
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -6363,11 +6366,11 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63636366
expanded as needed into the appropriate 2D arrays, making a
63646367
rectangular grid.
63656368
6366-
%(cmap_doc)s
6369+
%(multi_cmap_doc)s
63676370
6368-
%(norm_doc)s
6371+
%(multi_norm_doc)s
63696372
6370-
%(vmin_vmax_doc)s
6373+
%(multi_vmin_vmax_doc)s
63716374
63726375
%(colorizer_doc)s
63736376

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

0 commit comments

Comments
 (0)