heatMap Plot a 2D map of values as coloured patches


A heat map is a graphical representation of data where the values taken by a variable in a two-dimensional map are represented as colours. The "heatMap" quark provides the methods SequenceableCollection:heatMap and  Buffer:heatMap.


~aSequenceableCollection.heatMap(numChannels, bounds, xLabels, yLabels, title, win, showVals, colscheme)

~aBuffer.heatMap(bounds, xLabels, yLabels, title, win, showVals, colscheme)


Examples


Arrays:


// First let's create a random undulating distribution and look at it a few different ways:

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

a.plot;

a.heatMap(10);

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

a.heatMap(10, xLabels: true, yLabels: true, showVals: true, colscheme: \coals);


// A completely randomised set of values:

a = {1.0.sum3rand}.dup(100);

a.heatMap(10);

a.heatMap(10, Rect(0, 0, 100, 100));

a.heatMap(5, Rect(0, 0, 600, 200), showVals: true, xLabels: true);


// This distribution is interesting, but .plot doesn't really show why:

a = 20.collect{|x|20.collect{|y| (x+y/pi).sin.rand}}.flat;

a.plot(numChannels:20);

a.heatMap(20); // Much better!

// Choose your colour scheme:

a.heatMap(20, colscheme: \red);

a.heatMap(20, colscheme: \brw);

a.heatMap(20, colscheme: \coals);


// A larger dataset:

~datasize = 200; // if using SwingOSC, reduce this to about 100 at most

a = ~datasize.collect{|x| ~datasize.collect{|y| (x-y/0.1/(x+1)).sin.rand}}.flat;

a.heatMap(~datasize, Rect(0,0, 600, 600), showVals: false);



Buffers:


s.boot;

~testbuf = Buffer.alloc(s, 100, 7);

(

x = {

RecordBuf.ar(SinOsc.ar(1000, (0..6)) + WhiteNoise.ar(0.75), ~testbuf);

Line.kr(1,1, 100/44100, doneAction:2);

}.play;

)

~testbuf.plot

~testbuf.heatMap