plotter: Is current "uniformness" of heatmap coloring intentional?
- Dominant language
- Go
- Stars
- 3k
- Forks
- 201
- PR merge metrics
- No merged PRs in 30d
Description
### What are you trying to do?
Drawing heatmap.
### What did you do?
```go
func TestHeatMap(t *testing.T) {
m := offsetUnitGrid{
XOffset: -2,
YOffset: -1,
Data: mat.NewDense(3, 4, []float64{
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
}),
}
pal := myPalette{}
h := plotter.NewHeatMap(m, pal)
p := plot.New()
p.Add(h)
p.X.Padding = 0
p.Y.Padding = 0
img := vgimg.New(250, 175)
dc := draw.New(img)
p.Draw(dc)
w, err := os.Create("golden_files/heatMap.png")
if err != nil {
log.Panic(err)
}
png := vgimg.PngCanvas{Canvas: img}
if _, err = png.WriteTo(w); err != nil {
t.Fatal(err)
}
}
type myPalette struct{}
func (myPalette) Colors() []color.Color {
return []color.Color{
color.RGBA{R: 255, A: 255},
color.RGBA{G: 255, A: 255},
color.RGBA{B: 255, A: 255},
color.RGBA{R: 255, G: 255, A: 255},
}
}
// offsetUnitGrid is copied from https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat_test.go#L21
```
### What did you expect to happen?
Each color is used "uniformly". I consider 3 cells for each colors (3 * 4 = 12) is "unform".
Following code comments says palette is scaled uniformly across the data range.
https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat.go#L157
### What actually happened?
2 cells for red, 4 cells for green, 4 cells for blue, 2 cells for yellow. This doesn't look uniform to me.

Probably first color and last color have half chance to be used compared the other colors.
In my thought, following should be `ps := float64(len(pal)) / (h.Max - h.Min)`
https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat.go#L157-L158
and following shouldbe `col = pal[int((v-h.Min)*ps)]` to get uniform.
https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat.go#L222-L224
### What version of Go and Gonum/plot are you using?
```
go version go1.22.0 darwin/arm64
gonum.org/v1/plot v0.14.0
```
### Does this issue reproduce with the current master?
Not experimented yet. Maybe yes.
Contributor guide
Assessment
This issue has not been assessed yet.