matplotlib.pyplot.spy#

matplotlib.pyplot.spy(Z,*,precision=0,marker=None,markersize=None,aspect='equal',origin='upper',**kwargs)[source]#

Plot the sparsity pattern of a 2D array.

This visualizes the non-zero values of the array.

Two plotting styles are available: image and marker. Bothare available for full arrays, but only the marker styleworks forscipy.sparse.spmatrix instances.

Image style

Ifmarker andmarkersize areNone,imshow is used. Anyextra remaining keyword arguments are passed to this method.

Marker style

IfZ is ascipy.sparse.spmatrix ormarker ormarkersize areNone, aLine2D object will be returned with the value of markerdetermining the marker type, and any remaining keyword argumentspassed toplot.

Parameters:
Z(M, N) array-like

The array to be plotted.

precisionfloat or 'present', default: 0

Ifprecision is 0, any non-zero value will be plotted. Otherwise,values of\(|Z| > precision\) will be plotted.

Forscipy.sparse.spmatrix instances, you can alsopass 'present'. In this case any value present in the arraywill be plotted, even if it is identically zero.

aspect{'equal', 'auto', None} or float, default: 'equal'

The aspect ratio of the Axes. This parameter is particularlyrelevant for images since it determines whether data pixels aresquare.

This parameter is a shortcut for explicitly callingAxes.set_aspect. See there for further details.

  • 'equal': Ensures an aspect ratio of 1. Pixels will be square.

  • 'auto': The Axes is kept fixed and the aspect is adjusted sothat the data fit in the Axes. In general, this will result innon-square pixels.

  • None: UsercParams["image.aspect"] (default:'equal').

origin{'upper', 'lower'}, default:rcParams["image.origin"] (default:'upper')

Place the [0, 0] index of the array in the upper left or lower leftcorner of the Axes. The convention 'upper' is typically used formatrices and images.

Returns:
AxesImage orLine2D

The return type depends on the plotting style (see above).

Other Parameters:
**kwargs

The supported additional parameters depend on the plotting style.

For the image style, you can pass the following additionalparameters ofimshow:

For the marker style, you can pass anyLine2D property exceptforlinestyle:

Property

Description

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

float or None

animated

bool

antialiased oraa

bool

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

color orc

color

dash_capstyle

CapStyle or {'butt', 'projecting', 'round'}

dash_joinstyle

JoinStyle or {'miter', 'round', 'bevel'}

dashes

sequence of floats (on/off ink in points) or (None, None)

data

(2, N) array or two 1D arrays

drawstyle ords

{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'

figure

Figure orSubFigure

fillstyle

{'full', 'left', 'right', 'bottom', 'top', 'none'}

gapcolor

color or None

gid

str

in_layout

bool

label

object

linestyle orls

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidth orlw

float

marker

marker style string,Path orMarkerStyle

markeredgecolor ormec

color

markeredgewidth ormew

float

markerfacecolor ormfc

color

markerfacecoloralt ormfcalt

color

markersize orms

float

markevery

None or int or (int, int) or slice or list[int] or float or (float, float) or list[bool]

mouseover

bool

path_effects

list ofAbstractPathEffect

picker

float or callable[[Artist, Event], tuple[bool, dict]]

pickradius

float

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

solid_capstyle

CapStyle or {'butt', 'projecting', 'round'}

solid_joinstyle

JoinStyle or {'miter', 'round', 'bevel'}

transform

unknown

url

str

visible

bool

xdata

1D array

ydata

1D array

zorder

float

Notes

Note

This is thepyplot wrapper foraxes.Axes.spy.

Examples usingmatplotlib.pyplot.spy#

Spy Demos

Spy Demos