8000 Cleanup image docs · matplotlib/matplotlib@ef94f9d · GitHub
[go: up one dir, main page]

Skip to content

Commit ef94f9d

Browse files
committed
Cleanup image docs
1 parent 569e12e commit ef94f9d

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

lib/matplotlib/image.py

Lines changed: 46 additions & 33 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
@@ -659,7 +658,7 @@ def contains(self, mouseevent):
659658
return inside, {}
660659

661660
def write_png(self, fname):
662-
"""Write the image to png file with fname"""
661+
"""Write the image to png file *fname*."""
663662
im = self.to_rgba(self._A[::-1] if self.origin == 'lower' else self._A,
664663
bytes=True, norm=True)
665664
PIL.Image.fromarray(im).save(fname, format="png")
@@ -733,15 +732,14 @@ def get_interpolation(self):
733732
'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric',
734733
'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos',
735734
or 'none'.
736-
737735
"""
738736
return self._interpolation
739737

740738
def set_interpolation(self, s):
741739
"""
742740
Set the interpolation method the image uses when resizing.
743741
744-
if None, use a value from rc setting. If 'none', the image is
742+
If None, use :rc:`image.interpolation`. If 'none', the image is
745743
shown as is without interpolating. 'none' is only supported in
746744
agg, ps and pdf backends and will fall back to 'nearest' mode
747745
for other backends.
@@ -750,8 +748,7 @@ def set_interpolation(self, s):
750748
----------
751749
s : {'antialiased', 'nearest', 'bilinear', 'bicubic', 'spline16',
752750
'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', \
753-
'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'}
754-
751+
'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None
755752
"""
756753
if s is None:
757754
s = rcParams['image.interpolation']
@@ -775,7 +772,7 @@ def set_resample(self, v):
775772
Parameters
776773
----------
777774
v : bool or None
778-
If None, use :rc:`image.resample` = True.
775+
If None, use :rc:`image.resample`.
779776
"""
780777
if v is None:
781778
v = rcParams['image.resample']
@@ -911,9 +908,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
911908
magnification, unsampled=unsampled)
912909

913910
def _check_unsampled_image(self, renderer):
914-
"""
915-
Return whether the image would be better drawn unsampled.
916-
"""
911+
"""Return whether the image would be better drawn unsampled."""
917912
return (self.get_interpolation() == "none"
918913
and renderer.option_scale_image())
919914

@@ -999,7 +994,7 @@ def __init__(self, ax, *, interpolation='nearest', **kwargs):
999994
"""
1000995
Parameters
1001996
----------
1002-
interpolation : {'nearest', 'bilinear'}
997+
interpolation : {'nearest', 'bilinear'}, default: 'nearest'
1003998
1004999
**kwargs
10051000
All other keyword arguments are identical to those of `.AxesImage`.
@@ -1091,8 +1086,8 @@ def set_interpolation(self, s):
10911086
"""
10921087
Parameters
10931088
----------
1094-
s : str, None
1095-
Either 'nearest', 'bilinear', or ``None``.
1089+
s : {'nearest', 'bilinear'} or None
1090+
If None, use :rc:`image.interpolation`.
10961091
"""
10971092
if s is not None and s not in ('nearest', 'bilinear'):
10981093
raise NotImplementedError('Only nearest neighbor and '
@@ -1137,12 +1132,26 @@ def __init__(self, ax,
11371132
**kwargs
11381133
):
11391134
"""
1140-
cmap defaults to its rc setting
1135+
ax : `~.axes.Axes`
1136+
The axes the image will belong to.
1137+
x, y : 1D array-like, optional
1138+
Monotonic arrays of length N+1 and M+1, respectively, specifying
1139+
rectangle boundaries. If not given, will default to ``range(N + 1)``
1140+
and ``range(M + 1)``, respectively.
1141+
A : array-like
1142+
The data to be color-coded. The interpretation depends on the shape:
11411143
1142-
cmap is a colors.Colormap instance
1143-
norm is a colors.Normalize instance to map luminance to 0-1
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 scalar
1150+
data to colors.
1151+
norm : `~matplotlib.colors.Normalize`
1152+
Maps luminance to 0-1.
1153+
**kwargs : `.Artist` properties
11441154
1145-
Additional kwargs are matplotlib.artist properties
11461155
"""
11471156
super().__init__(ax, norm=norm, cmap=cmap)
11481157
self.update(kwargs)
@@ -1192,13 +1201,18 @@ def set_data(self, x, y, A):
11921201
11931202
Parameters
11941203
----------
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
1204+
x, y : 1D array-like, optional
1205+
Monotonic arrays of length N+1 and M+1, respectively, specifying
1206+
rectangle boundaries. If not given, will default to
11981207
``range(N + 1)`` and ``range(M + 1)``, respectively.
11991208
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.
1209+
The data to be color-coded. The interpretation depends on the
1210+
shape:
1211+
1212+
- (M, N) ndarray or masked array: values to be colormapped
1213+
- (M, N, 3): RGB array F438
1214+
- (M, N, 4): RGBA array
1215+
12021216
"""
12031217
A = cbook.safe_masked_invalid(A, copy=True)
12041218
if x is None:
@@ -1473,17 +1487,15 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
14731487
values that map to the colormap color limits. If either *vmin*
14741488
or *vmax* is None, that limit is determined from the *arr*
14751489
min/max value.
1476-
cmap : str or `~matplotlib.colors.Colormap`, optional
1490+
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
14771491
A Colormap instance or registered colormap name. The colormap
14781492
maps scalar data to colors. It is ignored for RGB(A) data.
1479-
Defaults to :rc:`image.cmap` ('viridis').
14801493
format : str, optional
14811494
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this
14821495
is unset is documented under *fname*.
1483-
origin : {'upper', 'lower'}, optional
1496+
origin : {'upper', 'lower'}, default: :rc:`image.origin`
14841497
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').
1498+
left or lower left corner of the axes.
14871499
dpi : int
14881500
The DPI to store in the metadata of the file. This does not affect the
14891501
resolution of the output image.
@@ -1547,7 +1559,8 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
15471559

15481560

15491561
def pil_to_array(pilImage):
1550-
"""Load a `PIL image`_ and return it as a numpy int array.
1562+
"""
1563+
Load a `PIL image`_ and return it as a numpy int array.
15511564
15521565
.. _PIL image: https://pillow.readthedocs.io/en/latest/reference/Image.html
15531566
@@ -1629,14 +1642,14 @@ def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
16291642
thumbfile : str or file-like
16301643
The thumbnail filename.
16311644
1632-
scale : float, optional
1645+
scale : float, default: 0.1
16331646
The scale factor for the thumbnail.
16341647
1635-
interpolation : str, optional
1648+
interpolation : str, default: 'bilinear'
16361649
The interpolation scheme used in the resampling. See the
16371650
*interpolation* parameter of `~.Axes.imshow` for possible values.
16381651
1639-
preview : bool, optional
1652+
preview : bool, default: False
16401653
If True, the default backend (presumably a user interface
16411654
backend) will be used which will cause a figure to be raised if
16421655
`~matplotlib.pyplot.show` is called. If it is False, the figure is

0 commit comments

Comments
 (0)
0