Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c7e0de

Browse files
authored
Merge pull request#10982 from timhoffm/doc-axes-imshow
Improve docstring of Axes.imshow
2 parentscffca75 +f308ccc commit9c7e0de

File tree

1 file changed

+98
-56
lines changed

1 file changed

+98
-56
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 98 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5002,82 +5002,117 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
50025002
origin=None,extent=None,shape=None,filternorm=1,
50035003
filterrad=4.0,imlim=None,resample=None,url=None,**kwargs):
50045004
"""
5005-
Display an imageonthe axes.
5005+
Display an image, i.e. dataona 2D regular raster.
50065006
50075007
Parameters
50085008
----------
5009-
X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4)
5010-
Display the image in `X` to current axes. `X` may be an
5011-
array or a PIL image. If `X` is an array, it
5012-
can have the following shapes and types:
5009+
X : array-like or PIL image
5010+
The image data. Supported array shapes are:
50135011
5014-
- MxN -- values to be mapped (float or int)
5015-
- MxNx3 -- RGB (float or uint8)
5016-
- MxNx4 -- RGBA (float or uint8)
5012+
- (M, N): an image with scalar data. The data is visualized
5013+
using a colormap.
5014+
- (M, N, 3): an image with RGB values (float or uint8).
5015+
- (M, N, 4): an image with RGBA values (float or uint8), i.e.
5016+
including transparency.
50175017
5018-
MxN arrays are mapped to colors based on the `norm` (mapping
5019-
scalar to scalar) and the `cmap` (mapping the normed scalar to
5020-
a color).
5018+
The first two dimensions (M, N) define the rows and columns of
5019+
the image.
50215020
5022-
Elements of RGB and RGBA arrays represent pixels of an MxN image.
5023-
All values should be in the range [0 .. 1] for floats or
5021+
The RGB(A) values should be in the range [0 .. 1] for floats or
50245022
[0 .. 255] for integers. Out-of-range values will be clipped to
50255023
these bounds.
50265024
5027-
cmap : `~matplotlib.colors.Colormap`, optional, default: None
5028-
If None, default to rc `image.cmap` value. `cmap` is ignored
5029-
if `X` is 3-D, directly specifying RGB(A) values.
5025+
cmap : str or `~matplotlib.colors.Colormap`, optional
5026+
A Colormap instance or registered colormap name. The colormap
5027+
maps scalar data to colors. It is ignored for RGB(A) data.
5028+
Defaults to :rc:`image.cmap`.
50305029
5031-
aspect : ['auto' | 'equal' | scalar], optional, default: None
5032-
If 'auto', changes the image aspect ratio to match that of the
5033-
axes.
5030+
aspect : {'equal', 'auto'} or float, optional
5031+
Controls the aspect ratio of the axes. The aspect is of particular
5032+
relevance for images since it may distort the image, i.e. pixel
5033+
will not be square.
50345034
5035-
If 'equal', and `extent` is None, changes the axes aspect ratio to
5036-
match that of the image. If `extent` is not `None`, the axes
5037-
aspect ratio is changed to match that of the extent.
5035+
This parameter is a shortcut for explicitly calling
5036+
`.Axes.set_aspect`. See there for further details.
50385037
5039-
If None, default to rc ``image.aspect`` value.
5038+
- 'equal': Ensures an aspect ratio of 1. Pixels will be square
5039+
(unless pixel sizes are explicitly made non-square in data
5040+
coordinates using *extent*).
5041+
- 'auto': The axes is kept fixed and the aspect is adjusted so
5042+
that the data fit in the axes. In general, this will result in
5043+
non-square pixels.
5044+
5045+
Defaults to :rc:`image.aspect`.
5046+
5047+
interpolation : str, optional
5048+
The interpolation method used. If *None*
5049+
:rc:`image.interpolation` is used, which defaults to 'nearest'.
50405050
5041-
interpolation : string, optional, default: None
5042-
Acceptable values are 'none', 'nearest', 'bilinear', 'bicubic',
5051+
Supported values are 'none', 'nearest', 'bilinear', 'bicubic',
50435052
'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',
50445053
'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc',
5045-
'lanczos'
5054+
'lanczos'.
50465055
5047-
If `interpolation` is None, default to rc `image.interpolation`.
5048-
See also the `filternorm` and `filterrad` parameters.
5049-
If `interpolation` is 'none', then no interpolation is performed
5056+
If *interpolation* is 'none', then no interpolation is performed
50505057
on the Agg, ps and pdf backends. Other backends will fall back to
50515058
'nearest'.
50525059
5053-
norm : `~matplotlib.colors.Normalize`, optional, default: None
5054-
A `~matplotlib.colors.Normalize` instance is used to scale
5055-
a 2-D float `X` input to the (0, 1) range for input to the
5056-
`cmap`. If `norm` is None, use the default func:`normalize`.
5057-
If `norm` is an instance of `~matplotlib.colors.NoNorm`,
5058-
`X` must be an array of integers that index directly into
5059-
the lookup table of the `cmap`.
5060+
See
5061+
:doc:`/gallery/images_contours_and_fields/interpolation_methods`
5062+
for an overview of the supported interpolation methods.
50605063
5061-
vmin, vmax : scalar, optional, default: None
5062-
`vmin` and `vmax` are used in conjunction with norm to normalize
5063-
luminance data. Note if you pass a `norm` instance, your
5064-
settings for `vmin` and `vmax` will be ignored.
5064+
Some interpolation methods require an additional radius parameter,
5065+
which can be set by *filterrad*. Additionally, the antigrain image
5066+
resize filter is controlled by the parameter *filternorm*.
50655067
5066-
alpha : scalar, optional, default: None
5068+
norm : `~matplotlib.colors.Normalize`, optional
5069+
If scalar data are used, the Normalize instance scales the
5070+
data values to the canonical colormap range [0,1] for mapping
5071+
to colors. By default, the data range is mapped to the
5072+
colorbar range using linear scaling. This parameter is ignored for
5073+
RGB(A) data.
5074+
5075+
vmin, vmax : scalar, optional
5076+
When using scalar data and no explicit *norm*, *vmin* and *vmax*
5077+
define the data range that the colormap covers. By default,
5078+
the colormap covers the complete value range of the supplied
5079+
data. *vmin*, *vmax* are ignored if the *norm* parameter is used.
5080+
5081+
alpha : scalar, optional
50675082
The alpha blending value, between 0 (transparent) and 1 (opaque).
5068-
The ``alpha`` argument is ignored for RGBA input data.
5083+
This parameter is ignored for RGBA input data.
50695084
5070-
origin :['upper' |'lower'], optional, default: None
5085+
origin :{'upper','lower'}, optional
50715086
Place the [0,0] index of the array in the upper left or lower left
5072-
corner of the axes. If None, default to rc `image.origin`.
5087+
corner of the axes. The convention 'upper' is typically used for
5088+
matrices and images.
5089+
If not given, :rc:`image.origin` is used, defaulting to 'upper'.
5090+
5091+
Note that the vertical axes points upward for 'lower'
5092+
but downward for 'upper'.
5093+
5094+
extent : scalars (left, right, bottom, top), optional
5095+
The bounding box in data coordinates that the image will fill.
5096+
The image is stretched individually along x and y to fill the box.
50735097
5074-
extent : scalars (left, right, bottom, top), optional, default: None
5075-
The location, in data-coordinates, of the lower-left and
5076-
upper-right corners. If `None`, the image is positioned such that
5077-
the pixel centers fall on zero-based (row, column) indices.
5098+
The default extent is determined by the following conditions.
5099+
Pixels have unit size in data coordinates. Their centers are on
5100+
integer coordinates, and their center coordinates range from 0 to
5101+
columns-1 horizontally and from 0 to rows-1 vertically.
5102+
5103+
Note that the direction of the vertical axis and thus the default
5104+
values for top and bottom depend on *origin*:
5105+
5106+
- For ``origin == 'upper'`` the default is
5107+
``(-0.5, numcols-0.5, numrows-0.5, -0.5)``.
5108+
- For ``origin == 'lower'`` the default is
5109+
``(-0.5, numcols-0.5, -0.5, numrows-0.5)``.
5110+
5111+
See the example :doc:`/tutorials/intermediate/imshow_extent` for a
5112+
more detailed description.
50785113
50795114
shape : scalars (columns, rows), optional, default: None
5080-
For raw buffer images
5115+
For raw buffer images.
50815116
50825117
filternorm : bool, optional, default: True
50835118
A parameter for the antigrain image resize filter (see the
@@ -5088,17 +5123,26 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
50885123
that any sum of pixel weights must be equal to 1.0. So, the
50895124
filter function must produce a graph of the proper shape.
50905125
5091-
filterrad :scalar, optional, default: 4.0
5126+
filterrad :float > 0, optional, default: 4.0
50925127
The filter radius for filters that have a radius parameter, i.e.
5093-
when interpolation is one of: 'sinc', 'lanczos' or 'blackman'
5128+
when interpolation is one of: 'sinc', 'lanczos' or 'blackman'.
5129+
5130+
resample : bool, optional
5131+
When *True*, use a full resampling method. When *False*, only
5132+
resample when the output image is larger than the input image.
5133+
5134+
url : str, optional
5135+
Set the url of the created `.AxesImage`. See `.Artist.set_url`.
50945136
50955137
Returns
50965138
-------
50975139
image : `~matplotlib.image.AxesImage`
50985140
50995141
Other Parameters
51005142
----------------
5101-
**kwargs : `~matplotlib.artist.Artist` properties.
5143+
**kwargs : `~matplotlib.artist.Artist` properties
5144+
These parameters are passed on to the constructor of the
5145+
`.AxesImage` artist.
51025146
51035147
See also
51045148
--------
@@ -5110,7 +5154,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51105154
coordinates. In other words: the origin will coincide with the center
51115155
of pixel (0, 0).
51125156
5113-
Two typical representations are used for RGB images with an alpha
5157+
There are two common representations for RGB images with an alpha
51145158
channel:
51155159
51165160
- Straight (unassociated) alpha: R, G, and B channels represent the
@@ -5136,8 +5180,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51365180
ifim.get_clip_path()isNone:
51375181
# image does not already have clipping set, clip to axes patch
51385182
im.set_clip_path(self.patch)
5139-
#if norm is None and shape is None:
5140-
# im.set_clim(vmin, vmax)
51415183
ifvminisnotNoneorvmaxisnotNone:
51425184
im.set_clim(vmin,vmax)
51435185
else:
@@ -7287,7 +7329,7 @@ def matshow(self, Z, **kwargs):
72877329
72887330
Parameters
72897331
----------
7290-
Z : array-like(N, M)
7332+
Z : array-like(M, N)
72917333
The matrix to be displayed.
72927334
72937335
Returns

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp