diff --git a/plotter/heat_test.go b/plotter/heat_test.go index 9a25aaa3..3c29d227 100644 --- a/plotter/heat_test.go +++ b/plotter/heat_test.go @@ -5,6 +5,7 @@ package plotter import ( + "fmt" "log" "testing" @@ -48,7 +49,8 @@ func ExampleHeatMap() { 5, 6, 7, 8, 9, 10, 11, 12, })} - h := NewHeatMap(m, palette.Heat(12, 1)) + plte := palette.Heat(12, 1) + h := NewHeatMap(m, plte) p, err := plot.New() if err != nil { @@ -58,6 +60,16 @@ func ExampleHeatMap() { p.Add(h) + // Create a legend. + rng := h.Max - h.Min + thumbs := PaletteThumbnailers(plte) + for i := len(thumbs) - 1; i >= 0; i-- { + t := thumbs[i] + fmin := float64(i) / float64(len(thumbs)) + fmax := float64(i+1) / float64(len(thumbs)) + p.Legend.Add(fmt.Sprintf("%.2g - %.2g", h.Min+fmin*rng, h.Min+fmax*rng), t) + } + p.X.Padding = 0 p.Y.Padding = 0 p.X.Max = 1.5