Sparsity pattern of a matrix

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


plot::SparseMatrixplot(A, options)
plot::SparseMatrixplot(A, x = xmin .. xmax, y = ymin .. ymax, <a = amin .. amax>, options)
plot::SparseMatrixplot([row1, row2, …], options)
plot::SparseMatrixplot([row1, row2, …], x = xmin .. xmax, y = ymin .. ymax, <a = amin .. amax>, options)


plot::SparseMatrixplot(A) creates a 2D plot with the axes representing the rows and columns of the matrix A. For each nonzero entry of A a point is plotted, thus displaying sparsity patterns in the matrix.

plot::SparseMatrixplot interprets the indices of a matrix as x and y coordinates, respectively. The indices are ordered according to the standard orientation of the axes, i.e., low matrix indices are found in the lower left corner of the plot.

If x = xmin .. xmax is specified, the j-th column of an m×n matrix A corresponds to the coordinate .

If y = ymin .. ymax is specified, the i-th row corresponds to the coordinate .

If no coordinate range is specified, xmin = 1, xmax = n, and ymin = 1, ymax = m is used, i.e., the coordinate x = j corresponds to the j-th column, the coordinate y = i corresponds to the i-th row.

A point is plotted for each non-zero matrix entry Aij.

By default, the attribute PointColorType = Flat is used. The color of all points is given by PointColor.

With PointColorType = Dichromatic, a color blend from PointColor to PointColor2 is used to indicate the size of the non-zero matrix entries. The color of points corresponding to small entries Aij is PointColor. Large entries are colored with PointColor2.

Animations are triggered by specifying a range a = amin .. amax for a parameter a that is different from the variables x, y. Thus, in animations, both the ranges x = xmin .. xmax, y = ymin .. ymax as well as the animation range a = amin .. amax must be specified.


AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AntiAliasedantialiased lines and points?TRUE
Colorthe main colorRGB::MidnightBlue
Datathe (statistical) data to plot 
Framesthe number of frames in an animation50
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?FALSE
Namethe name of a plot object (for browser and legend) 
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
PointSizethe size of points1.0
PointColorthe color of pointsRGB::MidnightBlue
PointColor2secondary point color for color blendsRGB::Red
PointStylethe presentation style of pointsDiamonds
PointsVisiblevisibility of mesh pointsTRUE
PointColorTypepoint coloring typesFlat
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title 
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE
XMaxfinal value of parameter “x” 
XMininitial value of parameter “x” 
XNamename of parameter “x” 
XRangerange of parameter “x” 
YMaxfinal value of parameter “y” 
YMininitial value of parameter “y” 
YNamename of parameter “y” 
YRangerange of parameter “y” 


Example 1

We create a random matrix of dimension 100 ×200 with 1000 nonzero entries:

A := matrix::random(100, 200, 1000, frandom):

With PointColorType = Dichromatic, the color of the points indicates the size of the matrix entries:

plot(plot::SparseMatrixplot(A, PointColorType = Dichromatic)):

delete A:

Example 2

Choosing appropriate coordinate ranges, we let two sparse matrix plots overlap each other. The red points correspond to a sparse 10 ×10 matrix with 50 random entries. The blue points indicate the corresponding upper triangular form obtained by Gaussian elimination:

A := matrix::random(10, 10, 50, random(1..5)):
B := A::dom::gaussElim(A)[1]:
plot(plot::SparseMatrixplot(A, x = 1..10, y = 1..10, 
                            Color = RGB::Red),
     plot::SparseMatrixplot(B, x = 1.3..10.3, y = 1..10,
                            Color = RGB::Blue,
                            PointStyle = FilledCircles),
     PointSize = 2*unit::mm, Scaling = Constrained, 
     Axes = Frame)

delete A, B:



A matrix of category Cat::Matrix or an array containing real numerical values or expressions of the animation parameter a.

A is equivalent to the attribute Data.

row1, row2, …

The matrix rows: each row must be a list of real numerical values or expressions of the animation parameter a. All rows must have the same length.

row1, row2, … is equivalent to the attribute Data.


Name of the horizontal coordinate: an identifier or an indexed identifier. It is used as the title of the coordinate axis in x direction.

x is equivalent to the attribute XName.

xmin .. xmax

The range of the horizontal coordinate: xmin, xmax must be numerical real value or expressions of the animation parameter a.

xmin .. xmax is equivalent to the attributes XRange, XMin, XMax.


Name of the vertical coordinate: an identifier or an indexed identifier. It is used as the title of the coordinate axis in y direction.

y is equivalent to the attribute YName.

ymin .. ymax

The range of the vertical coordinate: ymin, ymax must be numerical real value or expressions of the animation parameter a.

ymin .. ymax is equivalent to the attributes YRange, YMin, YMax.


Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.

See Also

MuPAD Functions

MuPAD Graphical Primitives