5
$\begingroup$

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.

$\endgroup$
6
  • 5
    $\begingroup$ ... and what have you tried? $\endgroup$ Jan 9, 2013 at 20:05
  • $\begingroup$ 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. $\endgroup$
    – murray
    Jan 9, 2013 at 20:10
  • $\begingroup$ I would like it to be smooth and preferably red for high frequency and blue for low frequency. $\endgroup$ Jan 9, 2013 at 23:22
  • 1
    $\begingroup$ possible duplicate of How to create a heatmap from list of coordinates? $\endgroup$
    – Jens
    Jan 10, 2013 at 3:38
  • 1
    $\begingroup$ @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. $\endgroup$
    – Jens
    Jan 10, 2013 at 18:51

3 Answers 3

6
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Tally and ListDensityPlot is what I needed. Thanks! $\endgroup$ Jan 10, 2013 at 22:57
2
$\begingroup$
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

$\endgroup$
2
$\begingroup$
 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

$\endgroup$

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.