ArrayPlot

ArrayPlot[array]

generates a plot in which the values in an array are shown in a discrete array of squares.

Details and Options

  • ArrayPlot[array] by default arranges successive rows of array down the page and successive columns across, just as a table or grid would normally be formatted. »
  • If array contains 0s and 1s, the 1s will appear as black squares and the 0s as white squares.
  • ArrayPlot by default generates grayscale output, in which zero values are shown white, and the maximum positive or negative value is shown black. »
  • With an explicit setting for PlotRange, ArrayPlot by default makes the minimum value white and the maximum black.
  • The values in array can be quantities with units associated with them.
  • The following special entries can be used: »
  • Nonebackground color
    color directivespecified color
  • If array is ragged, shorter rows are treated as padded on the right with background. »
  • ArrayPlot has the same options as Graphics, with the following additions and changes:
  • AspectRatioAutomaticratio of height to width
    ClippingStyleNonehow to show cells whose values are clipped
    ColorFunctionAutomatichow each cell should be colored
    ColorFunctionScalingTruewhether to scale the argument to ColorFunction
    ColorRulesAutomaticrules for determining colors from values
    DataRangeAllthe range of and values to assume
    DataReversedFalsewhether to reverse the order of rows
    FrameAutomaticwhether to draw a frame around the plot
    FrameLabelNonelabels for rows and columns
    FrameTicksNonewhat ticks to include on the frame
    MaxPlotPointsInfinitythe maximum number of points to include
    MeshFalsewhether to draw a mesh
    MeshStyleGrayLevel[GoldenRatio-1]the style to use for a mesh
    PlotLegendsNonelegends for datasets
    PlotRangeAllthe range of values to plot
    PlotTheme$PlotThemeoverall theme for the plot
    TargetUnitsAutomaticunits to display in the plot
  • The rules given by ColorRules are applied to the value of each cell. The rules can involve patterns. »
  • If none of the rules in ColorRules apply, then ColorFunction is used to determine the color.
  • With the default setting ColorRules->Automatic, an explicit setting ColorFunction->f is used instead of ColorRules.
  • With ColorFunctionScaling->False, each value is supplied as the argument to any function given for ColorFunction. »
  • With ColorFunctionScaling->True, the values are scaled to lie between 0 and 1. »
  • If the color determined for a particular cell is None, the cell is rendered in the background color.
  • If no color is determined for a particular cell, the cell is rendered in a default dark red color.
  • With DataReversed->True, the order of rows is reversed, so that rows run from bottom to top, with the last row at the top.
  • With the setting FrameTicks->Automatic, ticks are placed at round integers, typically multiples of 5 or 10. »
  • With the setting FrameTicks->All, ticks are also placed at the minimum and maximum and . »
  • In explicit FrameTicks specifications, the tick coordinates are taken to refer to and .
  • With DataReversed->True, tick values decrease from top to bottom.
  • PlotRange->amax specifies that only those between 0 and amax should be shown. »
  • PlotRange->{amin,amax} specifies that between amin and amax should be shown.
  • PlotRange->{{imin,imax},{jmin,jmax}} shows only elements with and in the specified ranges. The topleft element has , . With the default setting DataReversed->False, increases down the page; increases to the right.
  • PlotRange->{ispec,jspec,aspec} shows only elements in the specified ranges of , , and value. »
  • With the default setting for ColorFunction, PlotRange->{amin,amax} specifies that values from amin to amax should be shown with gray scales varying from white to black.
  • Mesh->True draws mesh lines between each cell in the array.
  • Mesh->{mi,mj} gives mesh specifications for the and directions, respectively.
  • With the default setting Frame->Automatic, a frame is drawn only when Mesh->False.
  • For purposes of combining with other graphics, the array element is taken to cover a unit square centered at coordinate position , .
  • A setting DataRange->{{xmin,xmax},{ymin,ymax}} specifies that the centers of successive cells should be at equally spaced positions between xmin and xmax in the horizontal direction, and ymin and ymax in the vertical direction. With the default setting DataReversed->False, is centered at {xmin,ymax}.
  • With the default setting DataRange->All and DataReversed->False, the array element will be taken to cover a unit square centered at coordinate position , .
  • ArrayPlot returns Graphics[Raster[data],opts].
  • ArrayPlot works with SparseArray objects. »

Examples

open allclose all

Basic Examples  (6)

Plot an array of numbers:

Give explicit color directives to specify colors for individual cells:

Specify overall color rules:

Include a mesh:

Plot a table of data:

Use a standard blend as a color function:

Scope  (7)

By default, absolute values go from white to black:

Unknown or symbolic values are shown dark red:

Plot data with units:

Specify explicit colors for each cell:

Plot a ragged array, padding on the right:

Cells with value None are rendered like the background:

Plot a sparse array:

Options  (53)

AspectRatio  (2)

Make all cells square:

Use a different aspect ratio:

Background  (4)

Background is normally visible only around the edges:

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

Background also by default shows through for values outside the plot range:

ClippingStyle overrides background color:

ClippingStyle  (3)

The default is to show values outside the plot range in the background color:

Show values outside the plot range in red:

Show low values in blue and high values in red:

ColorFunction  (5)

Map values from 0 to 1 onto colors according to Hue:

Use a pure function as the color function:

Use a named color gradient from ColorData:

Show elements with value 1 as black and all others as white:

With ColorFunctionScaling->True, the values are first scaled to lie between 0 and 1:

ColorRules  (6)

Specify color rules for explicit values or patterns:

ColorFunction is used if no color rules apply:

The array can contain symbolic values:

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

Use any patterns in ColorRules:

Rules are used in the order given:

DataReversed  (4)

Reverse the order of rows:

The frame ticks give the original row numbers:

Reverse the order of rows and columns:

Reverse the order of columns:

Epilog  (3)

Use Epilog to superimpose other graphics:

The graphics can be translucent:

Epilog uses the standard Graphics coordinate system:

Frame  (1)

Do not use a frame:

FrameTicks  (6)

Put frame ticks at round numbers:

Include frame ticks for endpoints:

Frame ticks at specific values:

Frame ticks without a visible frame:

With a mesh included, Frame->True is required for frame ticks to be drawn:

Make the frame invisible:

MaxPlotPoints  (1)

Use MaxPlotPoints to limit the number of elements explicitly plotted in each direction:

Mesh  (5)

Insert mesh lines between all cells:

Insert 15 row mesh lines and 5 column mesh lines:

Insert mesh lines around the first 10 columns:

Use a sequence of colors for the mesh lines:

Insert mesh lines after the first and second rows:

MeshStyle  (2)

Default mesh style:

Make the mesh pink:

PlotLegends  (5)

No legend is used by default:

Generate a legend automatically:

PlotLegends automatically picks up ColorFunction:

Legend uses ColorRules as labels:

Use Placed to place legend outside the plot:

PlotRange  (5)

Plot all elements:

Plot only elements with values up to 3, leaving the rest white:

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

With specific plot range {amin,amax}, the colors range from white at amin to black at amax:

Plot positive elements only:

PlotTheme  (1)

Use a theme with detailed ticks and a legend:

Move the legend below the plot:

Applications  (11)

Plot a two-color cellular automaton evolution:

Plot a three-color cellular automaton evolution:

Use colors rather than gray levels:

Plot the imaginary parts of a discrete Fourier transform matrix:

Plot the inverse of a matrix, shading according to absolute value:

Show positive entries as black and others as white:

Create a list of array plots:

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

Plot image-processed data:

Plot a color map:

Use a special color for non-numeric data:

Digits of powers of 3 in base 2:

Plot a sparse matrix in black and white:

Properties & Relations  (7)

An empty array yields a blank picture:

Grid arranges elements the same way as ArrayPlot:

Raster arranges elements upside down and with colors reversed relative to ArrayPlot:

Make the array be shown the same way as in ArrayPlot:

Use MatrixPlot when entries have a big range and many different values:

Or for large sparse matrices:

Use ReliefPlot for medical and geographic data:

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

Use GraphPlot for visualizing adjacency matrices:

Possible Issues  (2)

ArrayPlot may not be able to distinguish between large numbers of different values:

Use MatrixPlot instead (or provide a custom ColorFunction):

Entries of very small relative absolute values may not be differentiable from zero:

MatrixPlot scales entries so that entries with small relative absolute values can still be seen:

Neat Examples  (2)

Plot the Sin function at integer points:

Introduced in 2004
 (5.1)
 |
Updated in 2007
 (6.0)
2012
 (9.0)
2014
 (10.0)
2020
 (12.1)