Colormap

Example usage

A simple example of applying a colormap on data:

from trollimage.colormap import rdbu
from trollimage.image import Image

img = Image(data, mode="L")

rdbu.set_range(-90 + 273.15, 30 + 273.15)
img.colorize(rdbu)

img.show()
_images/hayan_simple.png

A more complex example, with a colormap build from greyscale on one end, and spectral on the other, like this:

_images/my_cm.png
from trollimage.colormap import spectral, greys
from trollimage.image import Image

img = Image(data, mode="L")

greys.set_range(-40 + 273.15, 30 + 273.15)
spectral.set_range(-90 + 273.15, -40.00001 + 273.15)
my_cm = spectral + greys
img.colorize(my_cm)

img.show()
_images/hayan.png

Now applying a palette to the data, with sharp edges:

from trollimage.colormap import set3
from trollimage.image import Image

img = Image(data, mode="L")

set3.set_range(-90 + 273.15, 30 + 273.15)
img.palettize(set3)

img.show()
_images/phayan.png

API

A simple colormap module.

class trollimage.colormap.Colormap(*tuples)

The colormap object.

Initialize with tuples of (value, (colors)), like this:

Colormap((-75.0, (1.0, 1.0, 0.0)),
         (-40.0001, (0.0, 1.0, 1.0)),
         (-40.0, (1, 1, 1)),
         (30.0, (0, 0, 0)))

You can also concatenate colormaps together, try:

cm = cm1 + cm2
colorize(data)

Colorize a monochromatic array data, based on the current colormap.

palettize(data)

Palettize a monochromatic array data based on the current colormap.

reverse()

Reverse the current colormap in place.

set_range(min_val, max_val)

Set the range of the colormap to [min_val, max_val]

trollimage.colormap.colorbar(height, length, colormap)

Return the channels of a colorbar.

trollimage.colormap.colorize(arr, colors, values)

Colorize a monochromatic array arr, based colors given for values. Interpolation is used. values must be in ascending order.

trollimage.colormap.palettebar(height, length, colormap)

Return the channels of a palettebar.

trollimage.colormap.palettize(arr, colors, values)

From start values apply colors to data.

Default Colormaps

Colors from www.ColorBrewer.org by Cynthia A. Brewer, Geography, Pennsylvania State University.

Sequential Colormaps

blues

pict1

greens

pict2

greys

pict3

oranges

pict4

purples

pict5

reds

pict6

bugn

pict7

bupu

pict8

gnbu

pict9

orrd

pict10

pubu

pict11

pubugn

pict12

purd

pict13

rdpu

pict14

ylgn

pict15

ylgnbu

pict16

ylorbr

pict17

ylorrd

pict18

Diverging Colormaps

brbg

pict21

piyg

pict22

prgn

pict23

puor

pict24

rdbu

pict25

rdgy

pict26

rdylbu

pict27

rdylgn

pict28

spectral

pict29

Qualitative Colormaps

set1

_images/palette0.png

set2

_images/palette1.png

set3

_images/palette2.png

paired

_images/palette3.png

accent

_images/palette4.png

dark2

_images/palette5.png

pastel1

_images/palette6.png

pastel2

_images/palette7.png

Rainbow Colormap

Don’t use this one ! See here why

rainbow

pict30