vispy.color.colormap module#

class vispy.color.colormap.BaseColormap(colors=None)#

Bases: object

Class representing a colormap:

t in [0, 1] –> rgba_color

Parameters:
colorslist of lists, tuples, or ndarrays

The control colors used by the colormap (shape = (ncolors, 4)).

Notes

Must be overriden. Child classes need to implement:

glsl_mapstring

The GLSL function for the colormap. Use $color_0 to refer to the first color in colors, and so on. These are vec4 vectors.

map(item)function

Takes a (N, 1) vector of values in [0, 1], and returns a rgba array of size (N, 4).

colors = None#
glsl_map = None#
map(item)#

Return a rgba array for the requested items.

This function must be overriden by child classes.

This function doesn’t need to implement argument checking on item. It can always assume that item is a (N, 1) array of values between 0 and 1.

Parameters:
itemndarray

An array of values in [0,1].

Returns:
rgbandarray

An array with rgba values, with one color per item. The shape should be item.shape + (4,).

Notes

Users are expected to use a colormap with __getitem__() rather than map() (which implements a lower-level API).

texture_lut()#

Return a texture2D object for LUT after its value is set. Can be None.

texture_map_data = None#
class vispy.color.colormap.Colormap(colors, controls=None, interpolation='linear')#

Bases: BaseColormap

A colormap defining several control colors and an interpolation scheme.

Parameters:
colorslist of colors | ColorArray

The list of control colors. If not a ColorArray, a new ColorArray instance is created from this list. See the documentation of ColorArray.

controlsarray-like

The list of control points for the given colors. It should be an increasing list of floating-point number between 0.0 and 1.0. The first control point must be 0.0. The last control point must be 1.0. The number of control points depends on the interpolation scheme.

interpolationstr

The interpolation mode of the colormap. Default: ‘linear’. Can also be ‘zero’. If ‘linear’, ncontrols = ncolors (one color per control point). If ‘zero’, ncontrols = ncolors+1 (one color per bin).

Examples

Here is a basic example:

>>> from vispy.color import Colormap
>>> cm = Colormap(['r', 'g', 'b'])
>>> cm[0.], cm[0.5], cm[np.linspace(0., 1., 100)]
property interpolation#

The interpolation mode of the colormap

map(x)#

The Python mapping function from the [0,1] interval to a list of rgba colors

Parameters:
xarray-like

The values to map.

Returns:
colorslist

List of rgba colors.

texture_lut()#

Return a texture2D object for LUT after its value is set. Can be None.

class vispy.color.colormap.CubeHelixColormap(start=0.5, rot=1, gamma=1.0, reverse=True, nlev=32, minSat=1.2, maxSat=1.2, minLight=0.0, maxLight=1.0, **kwargs)#

Bases: Colormap

class vispy.color.colormap.Diverging(h_pos=20, h_neg=250, saturation=1.0, value=0.7, center='light')#

Bases: Colormap

class vispy.color.colormap.HSL(ncolors=6, hue_start=0, saturation=1.0, value=1.0, controls=None, interpolation='linear')#

Bases: Colormap

A colormap which is defined by n evenly spaced points in a circular color space.

This means that we change the hue value while keeping the saturation and value constant.

Parameters:
n_colorsint, optional

The number of colors to generate.

hue_startint, optional

The hue start value. Must be in the range [0, 360], the default is 0.

saturationfloat, optional

The saturation component of the colors to generate. The default is fully saturated (1.0). Must be in the range [0, 1.0].

valuefloat, optional

The value (brightness) component of the colors to generate. Must be in the range [0, 1.0], and the default is 1.0

controlsarray-like, optional

The list of control points for the colors to generate. It should be an increasing list of floating-point number between 0.0 and 1.0. The first control point must be 0.0. The last control point must be 1.0. The number of control points depends on the interpolation scheme.

interpolationstr, optional

The interpolation mode of the colormap. Default: ‘linear’. Can also be ‘zero’. If ‘linear’, ncontrols = ncolors (one color per control point). If ‘zero’, ncontrols = ncolors+1 (one color per bin).

class vispy.color.colormap.HSLuv(ncolors=6, hue_start=0, saturation=1.0, value=0.7, controls=None, interpolation='linear')#

Bases: Colormap

A colormap which is defined by n evenly spaced points in the HSLuv space.

Parameters:
n_colorsint, optional

The number of colors to generate.

hue_startint, optional

The hue start value. Must be in the range [0, 360], the default is 0.

saturationfloat, optional

The saturation component of the colors to generate. The default is fully saturated (1.0). Must be in the range [0, 1.0].

valuefloat, optional

The value component of the colors to generate or “brightness”. Must be in the range [0, 1.0], and the default is 0.7.

controlsarray-like, optional

The list of control points for the colors to generate. It should be an increasing list of floating-point number between 0.0 and 1.0. The first control point must be 0.0. The last control point must be 1.0. The number of control points depends on the interpolation scheme.

interpolationstr, optional

The interpolation mode of the colormap. Default: ‘linear’. Can also be ‘zero’. If ‘linear’, ncontrols = ncolors (one color per control point). If ‘zero’, ncontrols = ncolors+1 (one color per bin).

Notes

For more information about HSLuv colors see https://www.hsluv.org/

class vispy.color.colormap.MatplotlibColormap(name)#

Bases: Colormap

Use matplotlib colormaps if installed.

Parameters:
namestring

Name of the colormap.

class vispy.color.colormap.RedYellowBlueCyan(limits=(0.33, 0.66, 1.0))#

Bases: Colormap

A colormap which goes red-yellow positive and blue-cyan negative

Parameters:
limitsarray-like, optional

The limits for the fully transparent, opaque red, and yellow points.

class vispy.color.colormap.SingleHue(hue=200, saturation_range=[0.1, 0.8], value=1.0)#

Bases: Colormap

A colormap which is solely defined by the given hue and value.

Given the color hue and value, this color map increases the saturation of a color. The start color is almost white but still contains a hint of the given color, and at the end the color is fully saturated.

Parameters:
huescalar, optional

The hue refers to a “true” color, without any shading or tinting. Must be in the range [0, 360]. Defaults to 200 (blue).

saturation_rangearray-like, optional

The saturation represents how “pure” a color is. Less saturation means more white light mixed in the color. A fully saturated color means the pure color defined by the hue. No saturation means completely white. This colormap changes the saturation, and with this parameter you can specify the lower and upper bound. Default is [0.2, 0.8].

valuescalar, optional

The value defines the “brightness” of a color: a value of 0.0 means completely black while a value of 1.0 means the color defined by the hue without shading. Must be in the range [0, 1.0]. The default value is 1.0.

Notes

For more information about the hue values see the wikipedia page.

vispy.color.colormap.get_colormap(name)#

Obtain a colormap by name.

Parameters:
namestr | Colormap

Colormap name. Can also be a Colormap for pass-through.

Examples

>>> get_colormap('autumn')
>>> get_colormap('single_hue')
vispy.color.colormap.get_colormaps()#

Return the list of colormap names.

vispy.color.colormap.mix(colors, x, controls=None)#
vispy.color.colormap.smoothstep(edge0, edge1, x)#

Performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1.

vispy.color.colormap.step(colors, x, controls=None)#