HeatMap a 2D map of values as coloured patches

See the help file for heatMap for how to generate heatmaps.

Once generated, there are a few things you can do with the HeatMap object:

patches

Allows you to access the patches as a 2D array of GUI.textView objects.

highlight(x, y, colour)

Allows you to highlight a single point of interest, as follows:

// Some random data

a = (0..9).scramble.blendAt((0.1, 0.2 .. 9));

h = a.heatMap(10, Rect(0, 0, 300, 200), xLabels: true, yLabels: true, colscheme: \bw);

h.highlight(9.rand, 10.rand)

monitorBus(bus, rate, colour)

uses the highlight feature to create a Task reading the highlight location from a 2-channel control-rate Bus, as follows:

// Using the "h" created in the above example...

s.boot;

b = Bus.control(s, 2);

(

x = {

var pos = {LFNoise2.kr(2).range(0,8).round}.dup;

Out.kr(b, pos);

Out.ar(0, Pan2.ar(SinOsc.ar(pos[1].linexp(8,0,220,440), 0, 0.1), pos[0].linlin(0,8,-1,1)));

}.play(s);

)

t = h.monitorBus(b); // Returns a running Task

t.stop; x.free; b.free; // tidy up

*plot2DfileData(path, title, labels, rowlen=3, picsize=90, colscheme=\bw)

This convenience reads a file from path (in a format such as AIFF/WAV/etc) and plots a 2D heatmap for each channel, on the assumption that the file represents a SQUARE heatmap, having (edgelength * edgelength) frames in the datafile. This is the format used by SOMTrain and SOMRd, among others. The window prints out pretty nicely, on Mac at least.

The method returns an array containing two things: the parent window, and an array of the HeatMap objects.

// Note: this time "h" is going to be our array of heatmaps

#w, h = HeatMap.plot2DfileData(Local.datapath +/+ "MatchEQ/a11wlk01-features-SOMcoords.aiff", "Look at these data");

~location = 9.rand @ 10.rand; h.do{|hm| hm.highlight(~location.x, ~location.y)}; w.refresh