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

I have an array of data that has repeats in it. I want to generate a heatmap depending on how much repetition each point has, as in how many times it is repeated.

share|improve this question
... and what have you tried? – Dr. belisarius Jan 9 '13 at 20:05
It would have helped if you specified in what way you want to represent the various counts, e.g., as different colors, or as different intensities of a single color (possibly gray), and with what resolution, i.e., separation of points. – murray Jan 9 '13 at 20:10
I would like it to be smooth and preferably red for high frequency and blue for low frequency. – Richard Hum Jan 9 '13 at 23:22
possible duplicate of How to create a heatmap from list of coordinates? – Jens Jan 10 '13 at 3:38
@SjoerdC.deVries My opinion is that the question isn't specific enough to rule out that it's a duplicate, so without evidence to the contrary it's not useful to keep it open unless people want to do telepathy to answer this. – Jens Jan 10 '13 at 18:51
up vote 6 down vote accepted

Tally is good help in this case, it counts the number of occurances. Using this it's easy to construct a replacement rule that replaces each element with the number of occurances, which you can then plot.

bd = BinomialDistribution[10, 0.4];
m = RandomVariate[bd, {100, 100}];
counts = Tally[Flatten[m]]
rule = Rule @@@ counts
ArrayPlot[m /. rule, ColorFunction -> "Rainbow"]


share|improve this answer
Tally and ListDensityPlot is what I needed. Thanks! – Richard Hum Jan 10 '13 at 22:57
ArrayPlot[# /. Rule @@@ Tally@Flatten@#] &@RandomInteger[10, {20, 20}]

Mathematica graphics



data = RandomInteger[{0, 10}, {20, 20}];
f = Interpolation@Flatten[MapIndexed[{Sequence @@ #2, #1} &, # /. 
        Rule @@@ Tally@Flatten@# &@ data, {2}], 1];
DensityPlot[f[x, y], {x, 1, 20}, {y, 1, 20}, ColorFunction -> ColorData["TemperatureMap"]]

Mathematica graphics

share|improve this answer
 data = RandomInteger[10, {200, 2}];
 DensityHistogram[data, 11, "Count",
 Method -> {"DistributionAxes" -> "BoxWhisker"}, 
 ColorFunction -> "Rainbow",
 FrameTicks -> {Thread[{Range[0.5, 10.5, 1.], ToString /@ Range[0, 10, 1]}], 
 Thread[{Range[0.5, 10.5, 1.], ToString /@ Range[0, 10, 1]}]}]

enter image description here

share|improve this answer

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.