Back to Data Visualization

spy

Visualize sparsity pattern

Syntax

spy(S)
spy(S, linespec)
spy(S, markersize)

Description

Generates a graphical representation of the sparsity pattern of a matrix S. Nonzero values are displayed as markers at their (column, row) positions. The x-axis label shows "nz = N" where N is the number of nonzero elements.

Parameters

NameDescription
SInput matrix (sparse or full)
linespec(optional)Line specification for marker style (e.g., 'ro' for red circles)
markersize(optional)Marker size in points (default: auto-scaled based on matrix size)

Returns

null (renders chart inline)

Examples

Try It
>> A = eye(10);
spy(A)
Try It
>> B = rand(20, 20) > 0.8;
spy(B)
Try It
>> spy(magic(10) > 50, 'ro', 8)

See Also