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

Skip to content

Commit 90680bd

Browse files
committed
docstrings for multivariate plotting in imshow, pcolor and pcolormesh
1 parent 14e1205 commit 90680bd

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

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
@@ -5703,7 +5703,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57035703
"""
57045704
Display data as an image, i.e., on a 2D regular raster.
57055705
5706-
The input may either be actual RGB(A) data, or 2D scalar data, which
5706+
The input may either be actual RGB(A) data, or 2D data, which
57075707
will be rendered as a pseudocolor image. For displaying a grayscale
57085708
image, set up the colormapping using the parameters
57095709
``cmap='gray', vmin=0, vmax=255``.
@@ -5724,24 +5724,25 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57245724
- (M, N): an image with scalar data. The values are mapped to
57255725
colors using normalization and a colormap. See parameters *norm*,
57265726
*cmap*, *vmin*, *vmax*.
5727+
- (K, M, N): multiple images with scalar data. Must be used
5728+
with a multivariate or bivariate colormap. See *cmap*.
57275729
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
57285730
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
57295731
i.e. including transparency.
57305732
5731-
The first two dimensions (M, N) define the rows and columns of
5732-
the image.
5733+
Here M and N define the rows and columns of the image.
57335734
57345735
Out-of-range RGB(A) values are clipped.
57355736
5736-
%(cmap_doc)s
5737+
%(multi_cmap_doc)s
57375738
57385739
This parameter is ignored if *X* is RGB(A).
57395740
5740-
%(norm_doc)s
5741+
%(multi_norm_doc)s
57415742
57425743
This parameter is ignored if *X* is RGB(A).
57435744
5744-
%(vmin_vmax_doc)s
5745+
%(multi_vmin_vmax_doc)s
57455746
57465747
This parameter is ignored if *X* is RGB(A).
57475748
@@ -6080,9 +6081,10 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
60806081
60816082
Parameters
60826083
----------
6083-
C : 2D array-like
6084+
C : 2D array-like or list of 2D array-like objects
60846085
The color-mapped values. Color-mapping is controlled by *cmap*,
6085-
*norm*, *vmin*, and *vmax*.
6086+
*norm*, *vmin*, and *vmax*. Multiple arrays are only supported
6087+
when a bivariate or mulivariate colormap is used, see *cmap*.
60866088
60876089
X, Y : array-like, optional
60886090
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -6129,11 +6131,11 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
61296131
See :doc:`/gallery/images_contours_and_fields/pcolormesh_grids`
61306132
for more description.
61316133
6132-
%(cmap_doc)s
6134+
%(multi_cmap_doc)s
61336135
6134-
%(norm_doc)s
6136+
%(multi_norm_doc)s
61356137
6136-
%(vmin_vmax_doc)s
6138+
%(multi_vmin_vmax_doc)s
61376139
61386140
%(colorizer_doc)s
61396141
@@ -6320,12 +6322,13 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63206322
- (M, N) or M*N: a mesh with scalar data. The values are mapped to
63216323
colors using normalization and a colormap. See parameters *norm*,
63226324
*cmap*, *vmin*, *vmax*.
6325+
- (K, M, N): multiple images with scalar data. Must be used with
6326+
a multivariate or bivariate colormap. See *cmap*.
63236327
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
63246328
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
63256329
i.e. including transparency.
63266330
6327-
The first two dimensions (M, N) define the rows and columns of
6328-
the mesh data.
6331+
Here M and N define the rows and columns of the image.
63296332
63306333
X, Y : array-like, optional
63316334
The coordinates of the corners of quadrilaterals of a pcolormesh::
@@ -6356,11 +6359,11 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63566359
expanded as needed into the appropriate 2D arrays, making a
63576360
rectangular grid.
63586361
6359-
%(cmap_doc)s
6362+
%(multi_cmap_doc)s
63606363
6361-
%(norm_doc)s
6364+
%(multi_norm_doc)s
63626365
6363-
%(vmin_vmax_doc)s
6366+
%(multi_vmin_vmax_doc)s
63646367
63656368
%(colorizer_doc)s
63666369

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)