Skip to content

Commit

Permalink
Add thumbnailer for palette.Palette
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Apr 29, 2017
1 parent d6e130c commit f07c773
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plotter/heat_test.go
Expand Up @@ -5,6 +5,7 @@
package plotter

import (
"fmt"
"log"
"testing"

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit f07c773

Please sign in to comment.