Main Content

spy

Visualize sparsity pattern of matrix

  • Visualization of the sparsity pattern of matrix

Description

spy(S) plots the sparsity pattern of matrix S. 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,LineSpec) 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) specifies MarkerSize 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.

B = bucky;
spy(B)

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.

spy(B,'ro')

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.

spy(B,'ro',2)

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.

MarkerDescriptionResulting 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 NameShort NameAppearance
'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

  • format + is a text-based alternative for displaying the nonzero structure of a small matrix:

    format +
    eye(4)
    ans =
    
    +   
     +  
      + 
       +

Extended Capabilities

Version History

Introduced before R2006a

expand all