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?


2 Answers 2


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["http://exampledata.wolfram.com/hailey.dem.gz", "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.

  • 1
    $\begingroup$ It is a very old question, however, on the modern version and modern hardware, it might still be actual if displaying huge matrices. Then Image@Rescale or Colorize@Image@Rescale works the best for me. Grid@Transpose@{MatrixPlot[data, ColorFunction -> GrayLevel] // AbsoluteTiming, ArrayPlot[data, ColorFunction -> GrayLevel] // AbsoluteTiming, Image@Rescale[data] // AbsoluteTiming} gives approximately 2s, 1s, and 5ms. And on a larger data (e.g. data = DiskMatrix[1000, 4000]) I get 1.8s, 5.6s and 0.18s. $\endgroup$ Nov 17, 2019 at 13:06
  • $\begingroup$ @Oleg Have you tried my renderImage code from (21482)? I am curious how it compares on recent versions. (I still use v10.1) $\endgroup$
    – Mr.Wizard
    Dec 18, 2019 at 15:21

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.

  • $\begingroup$ Thanks. I just realized that the answer was in my question from a few months ago. I am sorry for being so silly! $\endgroup$
    – Andrew
    Aug 14, 2012 at 20:22
  • 3
    $\begingroup$ @Andrew, Your question is not silly. I found it useful! $\endgroup$ Aug 15, 2012 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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