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

Skip to content

Commit 476ba2a

Browse files
committed
ENH Added the origin option to spy
This option allows to place either the origin at the bottom of the axes, or at the top.
1 parent 97b5251 commit 476ba2a

1 file changed

Lines changed: 31 additions & 46 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6547,33 +6547,41 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
65476547
return spec, freqs, t, im
65486548

65496549
def spy(self, Z, precision=0, marker=None, markersize=None,
6550-
aspect='equal', **kwargs):
6550+
aspect='equal', origin="upper", **kwargs):
65516551
"""
65526552
Plot the sparsity pattern on a 2-D array.
65536553
6554-
Call signature::
6554+
``spy(Z)`` plots the sparsity pattern of the 2-D array *Z*.
65556555
6556-
spy(Z, precision=0, marker=None, markersize=None,
6557-
aspect='equal', **kwargs)
6556+
Parameters
6557+
----------
65586558
6559-
``spy(Z)`` plots the sparsity pattern of the 2-D array *Z*.
6559+
Z : sparse array (n, m)
6560+
The array to be plotted.
6561+
6562+
precision : float, optional, default: 0
6563+
If *precision* is 0, any non-zero value will be plotted; else,
6564+
values of :math:`|Z| > precision` will be plotted.
6565+
6566+
For :class:`scipy.sparse.spmatrix` instances, there is a special
6567+
case: if *precision* is 'present', any value present in the array
6568+
will be plotted, even if it is identically zero.
65606569
6561-
If *precision* is 0, any non-zero value will be plotted;
6562-
else, values of :math:`|Z| > precision` will be plotted.
6570+
origin : ["upper", "lower"], optional, default: "upper"
6571+
Place the [0,0] index of the array in the upper left or lower left
6572+
corner of the axes.
65636573
6564-
For :class:`scipy.sparse.spmatrix` instances, there is a
6565-
special case: if *precision* is 'present', any value present in
6566-
the array will be plotted, even if it is identically zero.
6574+
aspect : ['auto' | 'equal' | scalar], optional, default: "equal"
65676575
6568-
The array will be plotted as it would be printed, with
6569-
the first index (row) increasing down and the second
6570-
index (column) increasing to the right.
6576+
If 'equal', and `extent` is None, changes the axes aspect ratio to
6577+
match that of the image. If `extent` is not `None`, the axes
6578+
aspect ratio is changed to match that of the extent.
6579+
6580+
6581+
If 'auto', changes the image aspect ratio to match that of the
6582+
axes.
65716583
6572-
By default aspect is 'equal', so that each array element
6573-
occupies a square space; set the aspect kwarg to 'auto'
6574-
to allow the plot to fill the plot box, or to any scalar
6575-
number to specify the aspect ratio of an array element
6576-
directly.
6584+
If None, default to rc ``image.aspect`` value.
65776585
65786586
Two plotting styles are available: image or marker. Both
65796587
are available for full arrays, but only the marker style
@@ -6592,33 +6600,10 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
65926600
* *cmap*
65936601
* *alpha*
65946602
6595-
.. seealso::
6596-
6597-
:func:`~matplotlib.pyplot.imshow`
6598-
For image options.
6599-
6600-
For controlling colors, e.g., cyan background and red marks,
6601-
use::
6602-
6603-
cmap = mcolors.ListedColormap(['c','r'])
6604-
6605-
If *marker* or *markersize* is not *None*, useful kwargs include:
6606-
6607-
* *marker*
6608-
* *markersize*
6609-
* *color*
6610-
6611-
Useful values for *marker* include:
6612-
6613-
* 's' square (default)
6614-
* 'o' circle
6615-
* '.' point
6616-
* ',' pixel
6617-
6618-
.. seealso::
6619-
6620-
:func:`~matplotlib.pyplot.plot`
6621-
For plotting options
6603+
See also
6604+
---------
6605+
imshow : for image options.
6606+
plot : for plotting options
66226607
"""
66236608
if marker is None and markersize is None and hasattr(Z, 'tocoo'):
66246609
marker = 's'
@@ -6632,7 +6617,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
66326617
nr, nc = Z.shape
66336618
extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]
66346619
ret = self.imshow(mask, interpolation='nearest', aspect=aspect,
6635-
extent=extent, origin='upper', **kwargs)
6620+
extent=extent, origin=origin, **kwargs)
66366621
else:
66376622
if hasattr(Z, 'tocoo'):
66386623
c = Z.tocoo()

0 commit comments

Comments
 (0)