plot: gonum.org/v1/plot/palette/moreland Index | Examples | Files

package moreland

import "gonum.org/v1/plot/palette/moreland"

Package moreland provides color maps for pseudocoloring scalar fields. The color maps are described at http://www.kennethmoreland.com/color-advice/ and in the following publications:

"Why We Use Bad Color Maps and What You Can Do About It." Kenneth Moreland. In Proceedings of Human Vision and Electronic Imaging (HVEI), 2016. (To appear)

"Diverging Color Maps for Scientific Visualization." Kenneth Moreland. In Proceedings of the 5th International Symposium on Visual Computing, December 2009. DOI 10.1007/978-3-642-10520-3_9.

This Example gives examples of plots using the palettes in this package. The output can be found at https://github.com/gonum/plot/blob/master/palette/moreland/testdata/moreland_golden.png.

Code:

m := offsetUnitGrid{
    XOffset: -50,
    YOffset: -50,
    Data:    mat.NewDense(100, 100, nil),
}
for i := 0; i < 100; i++ {
    for j := 0; j < 100; j++ {
        x := float64(i-50) / 10
        y := float64(j-50) / 10
        v := math.Sin(x*x+y*y) / (x*x + y*y)
        m.Data.Set(i, j, v)
    }
}

const (
    rows = 3
    cols = 3
)
c := vgimg.New(vg.Points(800), vg.Points(800))
dc := draw.New(c)
tiles := draw.Tiles{
    Rows: rows,
    Cols: cols,
}
type paletteHolder struct {
    name string
    cmap palette.Palette
}
palettes := []paletteHolder{
    {
        name: "SmoothBlueRed",
        cmap: moreland.SmoothBlueRed().Palette(255),
    },
    {
        name: "SmoothBlueTan",
        cmap: moreland.SmoothBlueTan().Palette(255),
    },
    {
        name: "SmoothGreenPurple",
        cmap: moreland.SmoothGreenPurple().Palette(255),
    },
    {
        name: "SmoothGreenRed",
        cmap: moreland.SmoothGreenRed().Palette(255),
    },
    {
        name: "SmoothPurpleOrange",
        cmap: moreland.SmoothPurpleOrange().Palette(255),
    },
    {
        name: "BlackBody",
        cmap: moreland.BlackBody().Palette(255),
    },
    {
        name: "ExtendedBlackBody",
        cmap: moreland.ExtendedBlackBody().Palette(255),
    },
    {
        name: "Kindlmann",
        cmap: moreland.Kindlmann().Palette(255),
    },
    {
        name: "ExtendedKindlmann",
        cmap: moreland.ExtendedKindlmann().Palette(255),
    },
}

for i, plte := range palettes {

    h := plotter.NewHeatMap(m, plte.cmap)

    p, err := plot.New()
    if err != nil {
        log.Panic(err)
    }
    p.Title.Text = plte.name

    p.Add(h)

    p.X.Padding = 0
    p.Y.Padding = 0
    p.Draw(tiles.At(dc, i%cols, i/cols))
}

pngimg := vgimg.PngCanvas{Canvas: c}
f, err := os.Create("testdata/moreland.png")
if err != nil {
    log.Panic(err)
}
if _, err = pngimg.WriteTo(f); err != nil {
    log.Panic(err)
}

Index

Examples

Package Files

convert.go luminance.go moreland.go smooth.go

func BlackBody Uses

func BlackBody() palette.ColorMap

BlackBody is a Luminance-class ColorMap based on the colors of black body radiation. Although the colors are inspired by the wavelengths of light from black body radiation, the actual colors used are designed to be perceptually uniform. Colors of the desired brightness and hue are chosen, and then the colors are adjusted such that the luminance is perceptually linear (according to the CIE LAB color space).

func ExtendedBlackBody Uses

func ExtendedBlackBody() palette.ColorMap

ExtendedBlackBody is a Luminance-class ColorMap based on the colors of black body radiation with some blue and purple hues thrown in at the lower end to add some "color." The color map is similar to the default colors used in gnuplot. Colors of the desired brightness and hue are chosen, and then the colors are adjusted such that the luminance is perceptually linear (according to the CIE LAB color space).

func ExtendedKindlmann Uses

func ExtendedKindlmann() palette.ColorMap

ExtendedKindlmann is a Luminance-class ColorMap uses the colors from Kindlmann but also adds more hues by doing a more than 360 degree loop around the hues. This works because the endpoints have low saturation and very different brightness.

func Kindlmann Uses

func Kindlmann() palette.ColorMap

Kindlmann is a Luminance-class ColorMap that uses the colors first proposed in a paper by Kindlmann, Reinhard, and Creem. The map is basically the rainbow color map with the luminance adjusted such that it monotonically changes, making it much more perceptually viable.

Citation: Gordon Kindlmann, Erik Reinhard, and Sarah Creem. 2002. Face-based luminance matching for perceptual colormap generation. In Proceedings of the conference on Visualization '02 (VIS '02). IEEE Computer Society, Washington, DC, USA, 299-306.

func NewLuminance Uses

func NewLuminance(controls []color.Color) (palette.ColorMap, error)

NewLuminance creates a new Luminance ColorMap from the given controlColors. luminance is a color palette that interpolates between control colors in a way that ensures a linear relationship between the luminance of a color and the value it represents. If the luminance of the controls is not monotonically increasing, an error will be returned.

func NewSmoothDiverging Uses

func NewSmoothDiverging(start, end color.Color, convergeM float64) palette.DivergingColorMap

NewSmoothDiverging creates a new smooth diverging ColorMap as described in "Diverging Color Maps for Scientific Visualization." by Kenneth Moreland, in Proceedings of the 5th International Symposium on Visual Computing, December 2009. DOI 10.1007/978-3-642-10520-3_9.

start and end are the start- and end-point colors and convergeM is the magnitude of the convergence point in magnitude-saturation-hue (MSH) color space. Note that convergeM specifies the color of the convergence point; it does not specify the location of the convergence point.

func SmoothBlueRed Uses

func SmoothBlueRed() palette.DivergingColorMap

SmoothBlueRed is a SmoothDiverging-class ColorMap ranging from blue to red.

func SmoothBlueTan Uses

func SmoothBlueTan() palette.DivergingColorMap

SmoothBlueTan is a SmoothDiverging-class ColorMap ranging from blue to tan.

func SmoothGreenPurple Uses

func SmoothGreenPurple() palette.DivergingColorMap

SmoothGreenPurple is a SmoothDiverging-class ColorMap ranging from green to purple.

func SmoothGreenRed Uses

func SmoothGreenRed() palette.DivergingColorMap

SmoothGreenRed is a SmoothDiverging-class ColorMap ranging from green to red.

func SmoothPurpleOrange Uses

func SmoothPurpleOrange() palette.DivergingColorMap

SmoothPurpleOrange is a SmoothDiverging-class ColorMap ranging from purple to orange.

Package moreland imports 4 packages (graph) and is imported by 3 packages. Updated 2019-03-18. Refresh now. Tools for package owners.