Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have a matrix called data. It seems that I can plot data using either ArrayPlot or MatrixPlot:

data = {{1, 0, 1}, {0, 0, 1}};
imgSize = 200;
   ArrayPlot[data, ImageSize -> imgSize],
   MatrixPlot[data, ImageSize -> imgSize]


So, by default, ArrayPlot and MatrixPlot give just different styles, it seems. I can adjust style parameters to obtain the same style:

   ArrayPlot[data, ImageSize -> imgSize, FrameTicks -> All, 
    ColorRules -> {0 -> White, 1 -> Blue}],
   MatrixPlot[data, ImageSize -> imgSize, 
    ColorRules -> {0 -> White, 1 -> Blue}]


What, if anything, it is the fundamental difference between ArrayPlot and MatrixPlot?

share|improve this question
up vote 17 down vote accepted

This is speed vs. best visual representation question. In my experience ArrayPlot is much faster than MatrixPlot for large data sets:

data = Table[Sin[(-i^2 - j^2)/1000.^1.5], {i, 1000}, {j, 1000}];

Grid@Transpose@{MatrixPlot[data, ColorFunction -> GrayLevel] // 
    AbsoluteTiming, ArrayPlot[data, ColorFunction -> GrayLevel] // AbsoluteTiming}

enter image description here

So if you need speed for large data sets go with ArrayPlot, or even Raster. But for visuals use MatrixPlot, especially when entries have a big range and many different values:

data = Fourier[Table[UnitStep[i, 4 - i] UnitStep[j, 7 - j], {i, -50, 50}, {j, -50, 50}]];

MatrixPlot colors negative entries with cool colors and positive entries with warm colors. ArrayPlot uses gray scale. MatrixPlot rescales the matrix entries to differentiate values over a wide range. Compare:

#[data] & /@ {ArrayPlot, MatrixPlot}

enter image description here

SparseArray usually gets much better representation from MatrixPlot:

#[Import[ToFileName[{"LinearAlgebraExamples", "Data"}, 
     "west0381.mtx"]]] & /@ {ArrayPlot, MatrixPlot}

enter image description here

I would also recommend to look at some other related plotting functions that act on arrays. Applicability really depends on the data type. For example in the case of geographical data ReliefPlot (the last one) is a winner:

#[Import["", "Data"]] & /@ 
{ArrayPlot, Graphics[Raster[Rescale[#]]] &, MatrixPlot, ReliefPlot}

enter image description here

Usually it is a good thing to check the Properties and Relations section in the Documentation.

share|improve this answer

You need to look no further than... your own question! A fundamental difference between the two is that MatrixPlot is used to "visualize" the data, whereas ArrayPlot is used to plot the array elements exactly. MatrixPlot does some sort of compression of the axes especially when you have an array that's long in one dimension and thin in the other. For example:

list = Table[Table[RandomInteger[], {j, 1, 10}], {i, 1, 200}];
{MatrixPlot[list, FrameTicks -> None, ImageSize -> {300, 300}, 
    ColorRules -> {0 -> White, 1 -> Red}],
 ArrayPlot[list, FrameTicks -> None, ImageSize -> {300, 300}, 
    ColorRules -> {0 -> White, 1 -> Red}]} // Row

enter image description here

You can see that MatrixPlot (left) has distorted the aspect ratio and interpolated the colours even though you gave explicit ColorRules, whereas ArrayPlot (right) plots it exactly. In order to make MatrixPlot behave similarly, you'll need to set MaxPlotPoints as in Andy Ross' answer.

share|improve this answer
Thanks. I just realized that the answer was in my question from a few months ago. I am sorry for being so silly! – Andrew Aug 14 '12 at 20:22
@Andrew, Your question is not silly. I found it useful! – Gustavo Delfino Aug 15 '12 at 0:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.