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

Skip to content

Commit dfd1c60

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

File tree

1 file changed

+59
-35
lines changed

1 file changed

+59
-35
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 59 additions & 35 deletions
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*
@@ -7290,64 +7290,88 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
72907290

72917291
return spec, freqs, t, im
72927292

7293+
@docstring.dedent_interpd
72937294
def spy(self, Z, precision=0, marker=None, markersize=None,
72947295
aspect='equal', origin="upper", **kwargs):
72957296
"""
7296-
Plot the sparsity pattern on a 2-D array.
7297+
Plot the sparsity pattern of a 2D array.
7298+
7299+
This visualizes the non-zero values of the array.
7300+
7301+
Two plotting styles are available: image and marker. Both
7302+
are available for full arrays, but only the marker style
7303+
works for `scipy.sparse.spmatrix` instances.
72977304
7298-
``spy(Z)`` plots the sparsity pattern of the 2-D array *Z*.
7305+
**Image style**
7306+
7307+
If *marker* and *markersize* are *None*, `~.Axes.imshow` is used. Any
7308+
extra remaining kwargs are passed to this method.
7309+
7310+
**Marker style**
7311+
7312+
If *Z* is a `scipy.sparse.spmatrix` or *marker* or *markersize* are
7313+
*None*, a `~matplotlib.lines.Line2D` object will be returned with
7314+
the value of marker determining the marker type, and any
7315+
remaining kwargs passed to `~.Axes.plot`.
72997316
73007317
Parameters
73017318
----------
7302-
7303-
Z : sparse array (n, m)
7319+
Z : array-like (M, N)
73047320
The array to be plotted.
73057321
7306-
precision : float, optional, default: 0
7307-
If *precision* is 0, any non-zero value will be plotted; else,
7322+
precision : float or 'present', optional, default: 0
7323+
If *precision* is 0, any non-zero value will be plotted. Otherwise,
73087324
values of :math:`|Z| > precision` will be plotted.
73097325
7310-
For :class:`scipy.sparse.spmatrix` instances, there is a special
7311-
case: if *precision* is 'present', any value present in the array
7326+
For :class:`scipy.sparse.spmatrix` instances, you can also
7327+
pass 'present'. In this case any value present in the array
73127328
will be plotted, even if it is identically zero.
73137329
7314-
origin : ["upper", "lower"], optional, default: "upper"
7330+
origin : {'upper', 'lower'}, optional
73157331
Place the [0,0] index of the array in the upper left or lower left
7316-
corner of the axes.
7332+
corner of the axes. The convention 'upper' is typically used for
7333+
matrices and images.
7334+
If not given, :rc:`image.origin` is used, defaulting to 'upper'.
7335+
73177336
7318-
aspect : ['auto' | 'equal' | scalar], optional, default: "equal"
7337+
aspect : {'equal', 'auto', None} or float, optional
7338+
Controls the aspect ratio of the axes. The aspect is of particular
7339+
relevance for images since it may distort the image, i.e. pixel
7340+
will not be square.
73197341
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.
7342+
This parameter is a shortcut for explicitly calling
7343+
`.Axes.set_aspect`. See there for further details.
73237344
7345+
- 'equal': Ensures an aspect ratio of 1. Pixels will be square.
7346+
- 'auto': The axes is kept fixed and the aspect is adjusted so
7347+
that the data fit in the axes. In general, this will result in
7348+
non-square pixels.
7349+
- *None*: Use :rc:`image.aspect` (default: 'equal').
73247350
7325-
If 'auto', changes the image aspect ratio to match that of the
7326-
axes.
7351+
Default: 'equal'
73277352
7328-
If None, default to rc ``image.aspect`` value.
7353+
Returns
7354+
-------
7355+
ret : `~matplotlib.image.AxesImage` or `.Line2D`
7356+
The return type depends on the plotting style (see above).
73297357
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.
7358+
Other Parameters
7359+
----------------
7360+
**kwargs
7361+
The supported additional parameters depend on the plotting style.
73337362
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.
7363+
For the image style, you can pass the following additional
7364+
parameters of `~.Axes.imshow`:
73417365
7342-
If *marker* and *markersize* are *None*, useful kwargs include:
7366+
- *cmap*
7367+
- *alpha*
7368+
- *url*
7369+
- any `.Artist` properties (passed on to the `.AxesImage`)
73437370
7344-
* *cmap*
7345-
* *alpha*
7371+
For the marker style, you can pass any `.Line2D` property except
7372+
for *linestyle*:
73467373
7347-
See also
7348-
--------
7349-
imshow : for image options.
7350-
plot : for plotting options
7374+
%(Line2D)s
73517375
"""
73527376
if marker is None and markersize is None and hasattr(Z, 'tocoo'):
73537377
marker = 's'

0 commit comments

Comments
 (0)