spy
Visualize sparsity pattern of matrix
Description
spy(
plots the sparsity pattern of matrix
S
)S
. Nonzero values are colored while zero values are white. The plot
displays the number of nonzeros in the matrix, nz = nnz(S)
.
spy(___,
specifies
MarkerSize
)MarkerSize
to give the size of the markers using either of the previous
input argument combinations.
Examples
Plot Sparsity Pattern
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)
Specify the color and marker.
spy(B,'ro')
Also specify the marker size.
spy(B,'ro',2)
Input Arguments
S
— Input matrix
matrix
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
MarkerSize
— Size of markers
positive integer scalar
Size of markers, specified as a positive integer scalar.
Example: spy(A,3)
uses markers of size 3.
LineSpec
— Marker symbol and color
character vector | string
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 |
|
"+" | Plus sign |
|
"*" | Asterisk |
|
"." | Point |
|
"x" | Cross |
|
"_" | Horizontal line |
|
"|" | Vertical line |
|
"square" | Square |
|
"diamond" | Diamond |
|
"^" | Upward-pointing triangle |
|
"v" | Downward-pointing triangle |
|
">" | Right-pointing triangle |
|
"<" | Left-pointing triangle |
|
"pentagram" | Pentagram |
|
"hexagram" | Hexagram |
|
Color Name | Short Name | Appearance |
---|---|---|
'red' | 'r' |
|
'green' | 'g' |
|
'blue' | 'b' |
|
'cyan'
| 'c' |
|
'magenta' | 'm' |
|
'yellow' | 'y' |
|
'black' | 'k' |
|
'white' | 'w' |
|
Tips
format +
is a text-based alternative for displaying the nonzero structure of a small matrix:format + eye(4)
ans = + + + +
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
This function accepts GPU arrays, but does not run on a GPU.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
Usage notes and limitations:
This function operates on distributed arrays, but executes in the client MATLAB®.
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006aR2023a: Aspect ratio and marker size changes
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.
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)