Skip to content

Commit 71c597e

Browse files
committed
Improve docstring of Axes.spy
1 parent 391c0cb commit 71c597e

File tree

1 file changed

+56
-35
lines changed

1 file changed

+56
-35
lines changed

lib/matplotlib/axes/_axes.py

+56-35
Original file line numberDiff line numberDiff line change
@@ -5044,7 +5044,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
50445044
that the data fit in the axes. In general, this will result in
50455045
non-square pixels.
50465046
5047-
Defaults to :rc:`image.aspect`.
5047+
If not given, use :rc:`image.aspect` (default: 'equal').
50485048
50495049
interpolation : str, optional
50505050
The interpolation method used. If *None*
@@ -7293,61 +7293,82 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
72937293
def spy(self, Z, precision=0, marker=None, markersize=None,
72947294
aspect='equal', origin="upper", **kwargs):
72957295
"""
7296-
Plot the sparsity pattern on a 2-D array.
7296+
Plot the sparsity pattern of a 2D array.
72977297
7298-
``spy(Z)`` plots the sparsity pattern of the 2-D array *Z*.
7298+
This visualizes the non-zero values of the array.
7299+
7300+
Two plotting styles are available: image and marker. Both
7301+
are available for full arrays, but only the marker style
7302+
works for `scipy.sparse.spmatrix` instances.
7303+
7304+
**Image style**
7305+
7306+
If *marker* and *markersize* are *None*, `~.Axes.imshow` is used. Any
7307+
extra remaining kwargs are passed to this method.
7308+
7309+
**Marker style**
7310+
7311+
If *Z* is a `scipy.sparse.spmatrix` or *marker* or *markersize* are
7312+
*None*, a `~matplotlib.lines.Line2D` object will be returned with
7313+
the value of marker determining the marker type, and any
7314+
remaining kwargs passed to `~.Axes.plot`.
72997315
73007316
Parameters
73017317
----------
7302-
7303-
Z : sparse array (n, m)
7318+
Z : array-like (M, N)
73047319
The array to be plotted.
73057320
7306-
precision : float, optional, default: 0
7307-
If *precision* is 0, any non-zero value will be plotted; else,
7321+
precision : float or 'present', optional, default: 0
7322+
If *precision* is 0, any non-zero value will be plotted. Otherwise,
73087323
values of :math:`|Z| > precision` will be plotted.
73097324
7310-
For :class:`scipy.sparse.spmatrix` instances, there is a special
7311-
case: if *precision* is 'present', any value present in the array
7325+
For :class:`scipy.sparse.spmatrix` instances, you can also
7326+
pass 'present'. In this case any value present in the array
73127327
will be plotted, even if it is identically zero.
73137328
7314-
origin : ["upper", "lower"], optional, default: "upper"
7329+
origin : {'upper', 'lower'}, optional
73157330
Place the [0,0] index of the array in the upper left or lower left
7316-
corner of the axes.
7331+
corner of the axes. The convention 'upper' is typically used for
7332+
matrices and images.
7333+
If not given, :rc:`image.origin` is used, defaulting to 'upper'.
73177334
7318-
aspect : ['auto' | 'equal' | scalar], optional, default: "equal"
73197335
7320-
If 'equal', and `extent` is None, changes the axes aspect ratio to
7321-
match that of the image. If `extent` is not `None`, the axes
7322-
aspect ratio is changed to match that of the extent.
7336+
aspect : {'equal', 'auto', None} or float, optional
7337+
Controls the aspect ratio of the axes. The aspect is of particular
7338+
relevance for images since it may distort the image, i.e. pixel
7339+
will not be square.
73237340
7341+
This parameter is a shortcut for explicitly calling
7342+
`.Axes.set_aspect`. See there for further details.
73247343
7325-
If 'auto', changes the image aspect ratio to match that of the
7326-
axes.
7344+
- 'equal': Ensures an aspect ratio of 1. Pixels will be square
7345+
(unless pixel sizes are explicitly made non-square in data
7346+
coordinates using *extent*).
7347+
- 'auto': The axes is kept fixed and the aspect is adjusted so
7348+
that the data fit in the axes. In general, this will result in
7349+
non-square pixels.
7350+
- *None*: Use :rc:`image.aspect` (default: 'equal').
73277351
7328-
If None, default to rc ``image.aspect`` value.
7352+
Default: 'equal'
73297353
7330-
Two plotting styles are available: image or marker. Both
7331-
are available for full arrays, but only the marker style
7332-
works for :class:`scipy.sparse.spmatrix` instances.
7354+
Returns
7355+
-------
7356+
ret : `~matplotlib.image.AxesImage` or `.Line2D`
7357+
The return type depends on the plotting style (see above).
73337358
7334-
If *marker* and *markersize* are *None*, an image will be
7335-
returned and any remaining kwargs are passed to
7336-
:func:`~matplotlib.pyplot.imshow`; else, a
7337-
:class:`~matplotlib.lines.Line2D` object will be returned with
7338-
the value of marker determining the marker type, and any
7339-
remaining kwargs passed to the
7340-
:meth:`~matplotlib.axes.Axes.plot` method.
7359+
Additional Parameters
7360+
---------------------
7361+
**kwargs
7362+
The supported additional parameters depend on the plotting style.
73417363
7342-
If *marker* and *markersize* are *None*, useful kwargs include:
7364+
For the image style, you can pass any parameters supported by
7365+
`~.Axes.imshow`. Commonly used parameters include *cmap* and
7366+
*alpha*.
73437367
7344-
* *cmap*
7345-
* *alpha*
7368+
For the marker style, you can pass any parameters
7369+
supported by `~.Axes.plot. Commonly used parameters include
7370+
*color*, *marker* and *markersize*.
73467371
7347-
See also
7348-
--------
7349-
imshow : for image options.
7350-
plot : for plotting options
73517372
"""
73527373
if marker is None and markersize is None and hasattr(Z, 'tocoo'):
73537374
marker = 's'

0 commit comments

Comments
 (0)