# What is the fundamental difference between ArrayPlot and MatrixPlot?

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;
Grid[{{
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:

Grid[{{
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?

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} 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} SparseArray usually gets much better representation from MatrixPlot:

#[Import[ToFileName[{"LinearAlgebraExamples", "Data"},
"west0381.mtx"]]] & /@ {ArrayPlot, MatrixPlot} 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} Usually it is a good thing to check the Properties and Relations section in the Documentation.

• 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. – Oleg Soloviev Nov 17 '19 at 13:06
• @Oleg Have you tried my renderImage code from (21482)? I am curious how it compares on recent versions. (I still use v10.1) – Mr.Wizard Dec 18 '19 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 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.

• 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