Skip to content

colormap

colormap(name, n, interpolate=True)

Produces the RGB values for a specific color map.

Parameters:

Name Type Description Default
name str

Name of the colormap to produce. Currently, all of Cynthia Brewer's ColorBrewer maps are supported (colorbrewer2.org): BuGn,BuPu,GnBu,OrRd,PuBu,PuBuGn,PuRd,RdPu,YlGn,YlGnBu, YlOrBr,YlOrRd,Blues,Greens,Greys,Oranges,Purples,Reds, BrBG,PiYG,PRGn,PuOr,RdBu,RdGy,RdYlBu,RdYlGn,Spectral, Accent,Dark2,Paired,Pastel1,Pastel2,Set1,Set2,Set3.

required
n

How many colors of the color map to produce. If n is zero and interpolate is False, will return the maximum number of colors for this color map.

required
interpolate bool, optional (default True)

If this is set to True, then this function will return n colors, cubically interpolated from the entire color map. If this is set to False, then this function will return the first n colors of the colormap, and error if n is larger than the amount of available colors.

True

Returns:

Name Type Description
C numpy int array

Resulting colormap. It can be evaluated with constant interpolation.

See Also

apply_colormap.

Notes

Prof. Cynthia Brewer (Pennsylvania State University) has released the ColorBrewer color maps under the Apache 2.0 license (http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html)

Examples:

TODO

Source code in src/gpytoolbox/colormap.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def colormap(name, n, interpolate=True):
    """Produces the RGB values for a specific color map.

    Parameters
    ----------
    name : str
       Name of the colormap to produce. Currently, all of Cynthia Brewer's ColorBrewer maps are supported (colorbrewer2.org): `BuGn`,`BuPu`,`GnBu`,`OrRd`,`PuBu`,`PuBuGn`,`PuRd`,`RdPu`,`YlGn`,`YlGnBu`, `YlOrBr`,`YlOrRd`,`Blues`,`Greens`,`Greys`,`Oranges`,`Purples`,`Reds`, `BrBG`,`PiYG`,`PRGn`,`PuOr`,`RdBu`,`RdGy`,`RdYlBu`,`RdYlGn`,`Spectral`, `Accent`,`Dark2`,`Paired`,`Pastel1`,`Pastel2`,`Set1`,`Set2`,`Set3`.
    n: int
       How many colors of the color map to produce. If n is zero and interpolate is False, will return the maximum number
       of colors for this color map.
    interpolate : bool, optional (default True)
       If this is set to True, then this function will return `n` colors, cubically interpolated from the entire color map. If this is set to False, then this function will return the first `n` colors of the colormap, and error if `n` is larger than the amount of available colors.

    Returns
    -------
    C : numpy int array
       Resulting colormap. It can be evaluated with constant interpolation.

    See Also
    --------
    apply_colormap.

    Notes
    -----
    Prof. Cynthia Brewer (Pennsylvania State University) has released the
    ColorBrewer color maps under the Apache 2.0 license
    (http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html)

    Examples
    --------
    TODO
    """

    if interpolate:
        assert n>=1
        raw_C = colormap(name, n=0, interpolate=False)
        f = sp.interpolate.interp1d(np.linspace(0., 1., raw_C.shape[0]),
            raw_C, axis=0, kind='cubic')
        return f(np.linspace(0., 1., n))
    else:
        assert name in _all_cbrewer_colormaps, "This color map does not exist."
        if n==0:
            i = 1
            while i in _all_cbrewer_colormaps[name]:
                i += 1
            return _all_cbrewer_colormaps[name][i-1]
        else:
            assert n in _all_cbrewer_colormaps[name]
            return _all_cbrewer_colormaps[name][n]