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

Skip to content

Commit 6c6732f

Browse files
committed
Cleanup image docs
1 parent 569e12e commit 6c6732f

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

lib/matplotlib/image.py

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def composite_images(images, renderer, magnification=1.0):
7070
7171
renderer : `.RendererBase`
7272
73-
magnification : float
73+
magnification : float, default: 1
7474
The additional magnification to apply for the renderer in use.
7575
7676
Returns
@@ -303,8 +303,7 @@ def _get_scalar_alpha(self):
303303

304304
def changed(self):
305305
"""
306-
Call this whenever the mappable is changed so observers can
307-
update state
306+
Call this whenever the mappable is changed so observers can update.
308307
"""
309308
self._imcache = None
310309
self._rgbacache = None
@@ -627,9 +626,7 @@ def draw(self, renderer, *args, **kwargs):
627626
self.stale = False
628627

629628
def contains(self, mouseevent):
630-
"""
631-
Test whether the mouse event occurred within the image.
632-
"""
629+
"""Test whether the mouse event occurred within the image."""
633630
inside, info = self._default_contains(mouseevent)
634631
if inside is not None:
635632
return inside, info
@@ -659,7 +656,7 @@ def contains(self, mouseevent):
659656
return inside, {}
660657

661658
def write_png(self, fname):
662-
"""Write the image to png file with fname"""
659+
"""Write the image to png file *fname*."""
663660
im = self.to_rgba(self._A[::-1] if self.origin == 'lower' else self._A,
664661
bytes=True, norm=True)
665662
PIL.Image.fromarray(im).save(fname, format="png")
@@ -733,15 +730,14 @@ def get_interpolation(self):
733730
'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric',
734731
'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos',
735732
or 'none'.
736-
737733
"""
738734
return self._interpolation
739735

740736
def set_interpolation(self, s):
741737
"""
742738
Set the interpolation method the image uses when resizing.
743739
744-
if None, use a value from rc setting. If 'none', the image is
740+
If None, use :rc:`image.interpolation`. If 'none', the image is
745741
shown as is without interpolating. 'none' is only supported in
746742
agg, ps and pdf backends and will fall back to 'nearest' mode
747743
for other backends.
@@ -750,8 +746,7 @@ def set_interpolation(self, s):
750746
----------
751747
s : {'antialiased', 'nearest', 'bilinear', 'bicubic', 'spline16',
752748
'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', \
753-
'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'}
754-
749+
'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None
755750
"""
756751
if s is None:
757752
s = rcParams['image.interpolation']
@@ -775,7 +770,7 @@ def set_resample(self, v):
775770
Parameters
776771
----------
777772
v : bool or None
778-
If None, use :rc:`image.resample` = True.
773+
If None, use :rc:`image.resample`.
779774
"""
780775
if v is None:
781776
v = rcParams['image.resample']
@@ -862,7 +857,6 @@ class AxesImage(_ImageBase):
862857
When True, use a full resampling method. When False, only resample when
863858
the output image is larger than the input image.
864859
**kwargs : `.Artist` properties
865-
866860
"""
867861
def __str__(self):
868862
return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
@@ -911,9 +905,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
911905
magnification, unsampled=unsampled)
912906

913907
def _check_unsampled_image(self, renderer):
914-
"""
915-
Return whether the image would be better drawn unsampled.
916-
"""
908+
"""Return whether the image would be better drawn unsampled."""
917909
return (self.get_interpolation() == "none"
918910
and renderer.option_scale_image())
919911

@@ -999,7 +991,7 @@ def __init__(self, ax, *, interpolation='nearest', **kwargs):
999991
"""
1000992
Parameters
1001993
----------
1002-
interpolation : {'nearest', 'bilinear'}
994+
interpolation : {'nearest', 'bilinear'}, default: 'nearest'
1003995
1004996
**kwargs
1005997
All other keyword arguments are identical to those of `.AxesImage`.
@@ -1091,8 +1083,8 @@ def set_interpolation(self, s):
10911083
"""
10921084
Parameters
10931085
----------
1094-
s : str, None
1095-
Either 'nearest', 'bilinear', or ``None``.
1086+
s : {'nearest', 'bilinear'} or None
1087+
If None, use :rc:`image.interpolation`.
10961088
"""
10971089
if s is not None and s not in ('nearest', 'bilinear'):
10981090
raise NotImplementedError('Only nearest neighbor and '
@@ -1137,12 +1129,28 @@ def __init__(self, ax,
11371129
**kwargs
11381130
):
11391131
"""
1140-
cmap defaults to its rc setting
1141-
1142-
cmap is a colors.Colormap instance
1143-
norm is a colors.Normalize instance to map luminance to 0-1
1144-
1145-
Additional kwargs are matplotlib.artist properties
1132+
Parameters
1133+
----------
1134+
ax : `~.axes.Axes`
1135+
The axes the image will belong to.
1136+
x, y : 1D array-like, optional
1137+
Monotonic arrays of length N+1 and M+1, respectively, specifying
1138+
rectangle boundaries. If not given, will default to
1139+
``range(N + 1)`` and ``range(M + 1)``, respectively.
1140+
A : array-like
1141+
The data to be color-coded. The interpretation depends on the
1142+
shape:
1143+
1144+
- (M, N) ndarray or masked array: values to be colormapped
1145+
- (M, N, 3): RGB array
1146+
- (M, N, 4): RGBA array
1147+
1148+
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
1149+
The Colormap instance or registered colormap name used to map
1150+
scalar data to colors.
1151+
norm : `~matplotlib.colors.Normalize`
1152+
Maps luminance to 0-1.
1153+
**kwargs : `.Artist` properties
11461154
"""
11471155
super().__init__(ax, norm=norm, cmap=cmap)
11481156
self.update(kwargs)
@@ -1192,13 +1200,17 @@ def set_data(self, x, y, A):
11921200
11931201
Parameters
11941202
----------
1195-
x, y : 1D array-likes or None
1196-
Monotonic arrays of shapes (N + 1,) and (M + 1,), respectively,
1197-
specifying rectangle boundaries. If None, will default to
1203+
x, y : 1D array-like, optional
1204+
Monotonic arrays of length N+1 and M+1, respectively, specifying
1205+
rectangle boundaries. If not given, will default to
11981206
``range(N + 1)`` and ``range(M + 1)``, respectively.
11991207
A : array-like
1200-
(M, N) ndarray or masked array of values to be colormapped, or
1201-
(M, N, 3) RGB array, or (M, N, 4) RGBA array.
1208+
The data to be color-coded. The interpretation depends on the
1209+
shape:
1210+
1211+
- (M, N) ndarray or masked array: values to be colormapped
1212+
- (M, N, 3): RGB array
1213+
- (M, N, 4): RGBA array
12021214
"""
12031215
A = cbook.safe_masked_invalid(A, copy=True)
12041216
if x is None:
@@ -1473,17 +1485,15 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
14731485
values that map to the colormap color limits. If either *vmin*
14741486
or *vmax* is None, that limit is determined from the *arr*
14751487
min/max value.
1476-
cmap : str or `~matplotlib.colors.Colormap`, optional
1488+
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
14771489
A Colormap instance or registered colormap name. The colormap
14781490
maps scalar data to colors. It is ignored for RGB(A) data.
1479-
Defaults to :rc:`image.cmap` ('viridis').
14801491
format : str, optional
14811492
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this
14821493
is unset is documented under *fname*.
1483-
origin : {'upper', 'lower'}, optional
1494+
origin : {'upper', 'lower'}, default: :rc:`image.origin`
14841495
Indicates whether the ``(0, 0)`` index of the array is in the upper
1485-
left or lower left corner of the axes. Defaults to :rc:`image.origin`
1486-
('upper').
1496+
left or lower left corner of the axes.
14871497
dpi : int
14881498
The DPI to store in the metadata of the file. This does not affect the
14891499
resolution of the output image.
@@ -1547,7 +1557,8 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
15471557

15481558

15491559
def pil_to_array(pilImage):
1550-
"""Load a `PIL image`_ and return it as a numpy int array.
1560+
"""
1561+
Load a `PIL image`_ and return it as a numpy int array.
15511562
15521563
.. _PIL image: https://pillow.readthedocs.io/en/latest/reference/Image.html
15531564
@@ -1629,14 +1640,14 @@ def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
16291640
thumbfile : str or file-like
16301641
The thumbnail filename.
16311642
1632-
scale : float, optional
1643+
scale : float, default: 0.1
16331644
The scale factor for the thumbnail.
16341645
1635-
interpolation : str, optional
1646+
interpolation : str, default: 'bilinear'
16361647
The interpolation scheme used in the resampling. See the
16371648
*interpolation* parameter of `~.Axes.imshow` for possible values.
16381649
1639-
preview : bool, optional
1650+
preview : bool, default: False
16401651
If True, the default backend (presumably a user interface
16411652
backend) will be used which will cause a figure to be raised if
16421653
`~matplotlib.pyplot.show` is called. If it is False, the figure is

0 commit comments

Comments
 (0)