...

Source file src/gonum.org/v1/plot/palette/reverse_example_test.go

Documentation: gonum.org/v1/plot/palette

     1  // Copyright ©2017 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package palette_test
     6  
     7  import (
     8  	"log"
     9  	"strconv"
    10  
    11  	"gonum.org/v1/plot"
    12  	"gonum.org/v1/plot/palette"
    13  	"gonum.org/v1/plot/palette/moreland"
    14  	"gonum.org/v1/plot/plotter"
    15  )
    16  
    17  // This example creates a color bar and a second color bar where the
    18  // direction of the colors are reversed.
    19  func ExampleReverse() {
    20  	p := plot.New()
    21  	l := &plotter.ColorBar{ColorMap: moreland.Kindlmann()}
    22  	l2 := &plotter.ColorBar{ColorMap: palette.Reverse(moreland.Kindlmann())}
    23  	l.ColorMap.SetMin(0.5)
    24  	l.ColorMap.SetMax(2.5)
    25  	l2.ColorMap.SetMin(2.5)
    26  	l2.ColorMap.SetMax(4.5)
    27  
    28  	p.Add(l, l2)
    29  	p.HideY()
    30  	p.X.Padding = 0
    31  	p.Title.Text = "A ColorMap and its Reverse"
    32  
    33  	if err := p.Save(300, 48, "testdata/reverse.png"); err != nil {
    34  		log.Panic(err)
    35  	}
    36  }
    37  
    38  // This example creates a color palette from a reversed ColorMap.
    39  func ExampleReverse_palette() {
    40  	p := plot.New()
    41  	thumbs := plotter.PaletteThumbnailers(palette.Reverse(moreland.Kindlmann()).Palette(10))
    42  	for i, t := range thumbs {
    43  		p.Legend.Add(strconv.Itoa(i), t)
    44  	}
    45  	p.HideAxes()
    46  	p.X.Padding = 0
    47  	p.Y.Padding = 0
    48  
    49  	if err := p.Save(35, 120, "testdata/reverse_palette.png"); err != nil {
    50  		log.Panic(err)
    51  	}
    52  }
    53  

View as plain text