-
Notifications
You must be signed in to change notification settings - Fork 0
/
heatmap.go
47 lines (40 loc) · 846 Bytes
/
heatmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2012 - 2014 The Seriation Authors. All rights reserved. See the LICENSE file.
package ser
// Heat Map
import (
"code.google.com/p/plotinum/plot"
"code.google.com/p/plotinum/plotter"
)
// Heat Map plots a heatmap of a matrix.
func HeatMap(mat Matrix64) {
heatData := getData(mat)
p, err := plot.New()
if err != nil {
panic(err)
}
bs, err := plotter.NewHeatMap(heatData)
if err != nil {
panic(err)
}
bs.Colorer = plotter.GoldRamp3
p.Add(bs)
if err := p.Save(4, 4, "heatmap.svg"); err != nil {
panic(err)
}
}
// getData fetches a data matrix.
func getData(a Matrix64) plotter.XYZs {
n := len(a)
m := len(a[0])
data := make(plotter.XYZs, n*m)
k := 0
for i := 0; i < n; i++ {
for j := 0; j < m; j++ {
data[k].X = float64(i)
data[k].Y = float64(j)
data[k].Z = a[i][j]
k++
}
}
return data
}