Discrete color bar in ArrayPlot

I made a plot of a matrix data (around 3000 columns x 2000 row) using ArrayPlot. The followings are the code and output.

As it is quite difficult to identify the value from a continuous color table, I would like to ask how to plot the graph with a discrete color table and the number of discrete colors can be defined by myself.

ArrayPlot[data, PlotRange -> Automatic,DataReversed -> {True, False}, ColorFunction -> ColorData["LightTemperatureMap"],PlotLegends -> {Style["Height (m)"], Placed[Automatic, Right]}]


• See here how to make a custom legend. – corey979 Mar 4 '17 at 10:38
• hi @corey979, thank you for the suggestion. I understand that discrete color table can be made via ContourPlot. However, it takes a very very long to generate a ContourPlot as the size of data is very large. So I select ArrayPlot. – wkong Mar 4 '17 at 16:19

From your example Using a given colour table with Image? might be applied here.
Please load the renderImage code from my answer there before evaluating the code below.

data = Import["http://exampledata.wolfram.com/hailey.dem.gz", "Data"];

Dimensions[data]

{1201, 1201}

legend = SwatchLegend[
Array[ColorData["LightTemperatureMap"], 5, {0, 1}],
Array[N, 5, {Min@data, Max@data}]
];

img =
renderImage[
Rescale @ data,
ColorData["LightTemperatureMap"], 5, ImageSize -> 300];

Labeled[img, legend, Right]


If this performs well for you I can write this into a single function, if you need help doing that.

• This is exactly what I need!! I will copy your code myself. Thanks a lot! – wkong Mar 6 '17 at 11:01
• Hi @Mr.Wizard In your example, there are 5 colors. May I ask what range each colour refers to? For example, the blue one is from 954 to 1615.5? The 2nd question is can I define another plot range? For example, range of the above data is 954 to 3600. Can I set the legend like {900, 1800, 2700, 3600}? Many thanks! – wkong Mar 7 '17 at 2:02
• @wkong I'll try to come back to this and provide better examples, but for now a brief comment: the original code uses Round; that could be replaced with Floor or Ceiling for different effects, or more complicated methods like Nearest or Interpolation could also be used. Additionally the legend above is likely poor because it doesn't really represent what is shown; explicit ranges like [1800, 2400] might be more clear. Whatever method is used (if Round is replaced) should be synchronized with the legend for accuracy. Clearly this will take a little work. – Mr.Wizard Mar 7 '17 at 3:58