sparse_display, an Octave code which can read information defining a matrix of numbers and display the sparsity pattern or location of the nonzero elements using gnuplot. This operation is already available in the built-in MATLAB spy() command.

The user can call "spy_ge" and pass in a matrix, in general (GE) format; the routine will then locate the nonzero entries, and write out a data file and a command file which together can be used to instruct gnuplot to create a sparsity plot.

If the user already has a file containing a list of pairs of indices (I,J) corresponding to nonzero matrix entries, then the user can call "spy_file", which will write out a command file only. Together, the user data file and the command file can be used to instruct gnuplot to create a sparsity plot.


The computer code and data files made available on this web page are distributed under the MIT license


sparse_display is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version.

Related Data and Programs:


cg, an Octave code which implements a simple version of the conjugate gradient (CG) method for solving a system of linear equations of the form A*x=b, suitable for situations in which the matrix A is positive definite (only real, positive eigenvalues) and symmetric.

gnuplot_test, an Octave code which illustrates how a program can write data and command files so that gnuplot can create plots of the program results.

mm_io, an Octave code which reads and writes sparse linear systems stored in the Matrix Market (MM) format.

wathen_matrix, an Octave code which compares storage schemes (full, banded, sparse triplet) and solution strategies (Linpack full, Linpack banded, conjugate gradient (CG)) for linear systems involving the Wathen matrix, which can arise when solving a problem using the finite element method (FEM).

Source Code:

Last revised on 15 January 2023.