WOLFRAM

generates a plot that gives a visual representation of the values of elements in a matrix.

Details and Options

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Plot a matrix as an array of colors:

Out[1]=1

Plot a matrix using only black and white:

Out[1]=1

Plot the structure of dense matrices:

Out[1]=1

Plot the structure of sparse matrices:

Out[1]=1
Out[2]=2

Scope  (19)Survey of the scope of standard use cases

Data  (10)

Plot a dense matrix:

Out[2]=2

Plot a sparse matrix:

Out[1]=1
Out[2]=2

Plot a nonrectangular "matrix", with missing entries transparent:

Out[1]=1

Negative entries are shown in cool colors, positive entries in warm colors, and zeros in white:

Out[1]=1

Entries near zero are shown in a shade of gray; entries very close to zero may be shown in white:

Out[1]=1

Complex numbers are shown based on their real parts:

Out[1]=1

None is interpreted as a missing value and displayed using transparency:

Out[1]=1

Symbolic values other than None are shown in dark red:

Out[1]=1

Colors are shown darker for very sparse matrices to make entries more visible:

Out[1]=1

Show a matrix with irrational and arbitrary-precision entries:

Out[1]=1

Presentation  (9)

Add labels:

Out[2]=2

Give explicit color directives to specify colors for individual cells:

Out[1]=1

Use a named color gradient:

Out[1]=1

Use a black-and-white color function to highlight the sparse structure of a matrix:

Out[1]=1
Out[2]=2

Use a custom color function with blue colors for negative values and red colors for positive values:

Out[1]=1

Use ColorRules to color different values:

Out[1]=1

Use both ColorRules and ColorFunction to color elements, giving priority to ColorRules:

Out[1]=1

Use Mesh and MeshStyle to provide an overlay mesh:

Out[1]=1

Use a plot theme:

Out[1]=1

Options  (33)Common values & functionality for each option

AspectRatio  (2)

Make all cells square:

Out[1]=1

Use a different aspect ratio:

Out[1]=1

Background  (2)

Background is normally visible only around the edges:

Out[1]=1

The background "shows through" whenever an explicit entry is None:

Out[1]=1

ClippingStyle  (3)

By default, the clipped values are colored vibrant red and blue:

Out[1]=1

Use explicit colors for the clipped values:

Out[1]=1

Use None to indicate no style, showing the background in those cells:

Out[1]=1

ColorFunction  (5)

Use an explicit color function:

Out[1]=1

Use a pure function as the color function:

Out[1]=1

Use a named color gradient from ColorData:

Out[1]=1

If the color function is undefined for some value, then a dark red is substituted:

Out[1]=1

In this case, the color is defined for all the values:

Out[2]=2

For complex matrices, the real part is used for the color function:

Out[1]=1
Out[2]=2

ColorFunctionScaling  (4)

By default, a nonlinear scaling of entries is used to differentiate values over a wide range:

Out[1]=1

With ColorFunctionScaling->False, entries are not scaled:

Out[1]=1

With ColorFunctionScaling->False, MatrixPlot behaves like ArrayPlot:

Out[1]=1
Out[2]=2

ColorFunctionScaling has no effect on ColorRules:

Out[1]=1

ColorRules  (6)

Specify color rules for explicit values or patterns:

Out[1]=1

Implement a "default color" by adding a rule for _:

Out[1]=1

The array can contain symbolic values:

Out[1]=1

Use any patterns in ColorRules:

Out[1]=1

Rules are used in the order given:

Out[1]=1

ColorRules can be used together with ColorFunction and has higher priority:

Out[1]=1

DataReversed  (1)

Reverse the order of columns:

Out[1]=1

MaxPlotPoints  (1)

By default, automatic methods are used to downsample large and/or sparse matrices:

Out[1]=1
Out[2]=2

Without downsampling, the entries are less visible:

Out[3]=3

Explicitly set downsampling values for MaxPlotPoints:

Out[4]=4

The visual appearance in the resulting plot is also affected by the choice of ColorFunction:

Out[5]=5

Mesh  (3)

Insert mesh lines between all cells:

Out[1]=1

Insert 19 row mesh lines and 1 column mesh line:

Out[1]=1

Use a sequence of colors for the mesh lines:

Out[1]=1

MeshStyle  (1)

Make the mesh pink:

Out[1]=1

PlotRange  (3)

Plot all elements:

Out[1]=1

Plot only elements with values from 0 to 1; clip the rest:

Out[1]=1

The first two entries in PlotRange specify the range of rows and columns to include:

Out[1]=1

PlotTheme  (2)

Use a theme with simple ticks and grid lines in a bright color scheme:

Out[1]=1

Turn off the grid lines:

Out[1]=1

Applications  (3)Sample problems that can be solved with this function

Plot a sparse matrix:

Out[1]=1
Out[2]=2

Zoom in to the top-left diagonal block:

Out[3]=3

Plot the imaginary parts of a discrete Fourier transform matrix:

Out[1]=1

Plot a table of values of five sine waves in random directions:

Out[1]=1

Properties & Relations  (6)Properties of the function, and connections to other functions

MatrixPlot colors negative entries with cool colors and positive entries with warm colors:

Out[1]=1

ArrayPlot uses gray scale:

Out[2]=2

MatrixPlot rescales the matrix entries to differentiate values over a wide range:

Out[1]=1

Without rescaling, fewer elements can be differentiated:

Out[2]=2

Use ReliefPlot for medical and geographic data:

Out[1]=1

Use ListDensityPlot for structured or unstructured data sampled from continuous densities:

Out[1]=1

Use ArrayPlot3D for 3D arrays of data:

Out[1]=1

Use GraphPlot for visualizing adjacency matrices:

Out[1]=1

Possible Issues  (2)Common pitfalls and unexpected behavior

Using MaxPlotPoints may result in artifacts not actually present in the original data:

Out[2]=2

With a small MaxPlotPoints option value, all entries become nonzero:

Out[3]=3

Entries very close to zero may be treated as zero:

Out[1]=1

Neat Examples  (1)Surprising or curious use cases

Plot the Sin function at integer points:

Out[1]=1
Wolfram Research (2007), MatrixPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixPlot.html (updated 2014).
Wolfram Research (2007), MatrixPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixPlot.html (updated 2014).

Text

Wolfram Research (2007), MatrixPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixPlot.html (updated 2014).

Wolfram Research (2007), MatrixPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixPlot.html (updated 2014).

CMS

Wolfram Language. 2007. "MatrixPlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/MatrixPlot.html.

Wolfram Language. 2007. "MatrixPlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/MatrixPlot.html.

APA

Wolfram Language. (2007). MatrixPlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MatrixPlot.html

Wolfram Language. (2007). MatrixPlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MatrixPlot.html

BibTeX

@misc{reference.wolfram_2025_matrixplot, author="Wolfram Research", title="{MatrixPlot}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MatrixPlot.html}", note=[Accessed: 28-March-2025 ]}

@misc{reference.wolfram_2025_matrixplot, author="Wolfram Research", title="{MatrixPlot}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MatrixPlot.html}", note=[Accessed: 28-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_matrixplot, organization={Wolfram Research}, title={MatrixPlot}, year={2014}, url={https://reference.wolfram.com/language/ref/MatrixPlot.html}, note=[Accessed: 28-March-2025 ]}

@online{reference.wolfram_2025_matrixplot, organization={Wolfram Research}, title={MatrixPlot}, year={2014}, url={https://reference.wolfram.com/language/ref/MatrixPlot.html}, note=[Accessed: 28-March-2025 ]}