spy - Visualize sparsity pattern of matrix - MATLAB (original) (raw)

Main Content

Visualize sparsity pattern of matrix

Syntax

Description

spy([S](#mw%5Fe75a4ddd-92fb-4f8c-8025-684dac464eb1)) plots the sparsity pattern of matrixS. Nonzero values are colored while zero values are white. The plot displays the number of nonzeros in the matrix, nz = nnz(S).

example

spy([S](#mw%5Fe75a4ddd-92fb-4f8c-8025-684dac464eb1),[LineSpec](#mw%5Fb163bd50-76a0-460a-9d99-e9d926196963)) additionally specifies LineSpec to give the marker symbol and color to use in the plot. For example, spy(A,'r*') uses red asterisks for nonzeros.

example

spy(___,[MarkerSize](#mw%5F0564a48d-a9ba-4656-a5f3-54a1322a485a)) specifiesMarkerSize to give the size of the markers using either of the previous input argument combinations.

example

Examples

collapse all

Plot the 60-by-60 sparse adjacency matrix of the connectivity graph of the Buckminster Fuller geodesic dome. This matrix also represents the carbon-60 molecule and a soccer ball.

Figure contains an axes object. The axes object with xlabel nz = 180 contains a line object which displays its values using only markers.

Specify the color and marker.

Figure contains an axes object. The axes object with xlabel nz = 180 contains a line object which displays its values using only markers.

Also specify the marker size.

Figure contains an axes object. The axes object with xlabel nz = 180 contains a line object which displays its values using only markers.

Input Arguments

collapse all

Input matrix. S is typically a sparse matrix, but can be either full or sparse.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
Complex Number Support: Yes

Size of markers, specified as a positive integer scalar.

Example: spy(A,3) uses markers of size 3.

Marker symbol and color, specified as a character vector or string containing symbols. The symbols can appear in any order. You do not need to specify both characteristics (marker and color). For example, if you omit the color and specify the marker, then the plot uses the default colors but uses the specified markers.

Example: 'or' uses red circle markers.

Marker Description Resulting Marker
"o" Circle Sample of circle marker
"+" Plus sign Sample of plus sign marker
"*" Asterisk Sample of asterisk marker
"." Point Sample of point marker
"x" Cross Sample of cross marker
"_" Horizontal line Sample of horizontal line marker
"|" Vertical line Sample of vertical line marker
"square" Square Sample of square marker
"diamond" Diamond Sample of diamond marker
"^" Upward-pointing triangle Sample of upward-pointing triangle marker
"v" Downward-pointing triangle Sample of downward-pointing triangle marker
">" Right-pointing triangle Sample of right-pointing triangle marker
"<" Left-pointing triangle Sample of left-pointing triangle marker
"pentagram" Pentagram Sample of pentagram marker
"hexagram" Hexagram Sample of hexagram marker
Color Name Short Name Appearance
'red' 'r' Sample of the color red
'green' 'g' Sample of the color green
'blue' 'b' Sample of the color blue
'cyan' 'c' Sample of the color cyan
'magenta' 'm' Sample of the color magenta
'yellow' 'y' Sample of the color yellow
'black' 'k' Sample of the color black
'white' 'w' Sample of the color white

Tips

Extended Capabilities

expand all

The spy function supports GPU array input with these usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a

expand all

The aspect ratio of spy plots has a 1-to-10 limit, after which the plot stops adjusting to the matrix shape. You can use pbaspect("auto") for no special aspect ratio or pbaspect([size(A,2) size(A,1) 1]) for the previous behavior of a matching aspect ratio, even for very "squeezed" cases.

Additionally, the default marker size is based only on the matrix size. Previously, the point size of the axes on creation could also affect the marker size.