Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
5  
... and what have you tried? –  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. –  alfonzo1955 Jan 9 '13 at 23:22
1  
possible duplicate of How to create a heatmap from list of coordinates? –  Jens Jan 10 '13 at 3:38
1  
@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
show 1 more comment

3 Answers

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"]

ArrayPlot

share|improve this answer
    
Tally and ListDensityPlot is what I needed. Thanks! –  alfonzo1955 Jan 10 '13 at 22:57
add comment
 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
add comment
ArrayPlot[# /. Rule @@@ Tally@Flatten@#] &@RandomInteger[10, {20, 20}]

Mathematica graphics

Edit

Smoothing:

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
add comment

Your Answer

 
discard

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.