Colors

Blendable colors and colormaps.

class storylines.color.Color(A, B, C, model='RGB')[source]

Representation of a color.

Colors can be defined using different models:

RGB (red, green, blue):

The three RGB channels take values from 0 to 255.

HSV (hue, saturation, value):

The hue is the color angle in degrees from 0 to 360. Values of 0, 120, and 240 correspond to red, green, and blue. The saturation takes values from -1 to 1. A value of 0 is white; negative values yield complementary colors. The value is the RGB amplitude from 0 to 255. A value of 0 is black.

PSV (phase, shift, value):

Superposition of shifted RGB “waves”. The phase and the phase shift from R to G (G to B) are in radians. The value is the amplitude of the wave from 0 to 255.

Colors can be mixed:

red = Color(255, 0, 0, 'RGB')
green = Color(120, 1, 255, 'HSV')
yellow = (red + green) / 2

Here, colors of different models are converted to RGB first.

RGB()[source]

Calculate red, green, and blue components.

toHSV()[source]

Create HSV representation.

toRGB()[source]

Create RGB representation.

storylines.color.HSV2RGB(H, S=1, V=255)[source]

Transform hue, saturation, value to red, green, blue.

Parameters:
Hfloat

Hue with period of 360 (degrees).

Sfloat

Saturation between 0 and 1.

Vfloat

Value/brightness between 0 and 255.

Returns:
float, float, float

Red, green, and blue values between 0 an 255.

storylines.color.PSV2RGB(P, S=1, V=255)[source]

Set color via phase, shift, and value.

Parameters:
Pfloat

Phase between 0 and 2 pi.

Sfloat

Phase shift from red to green and from green to blue channel between 0 and 2 pi.

Vfloat

Value/brightness between 0 and 255.

Returns:
float, float, float

Red, green, and blue values between 0 an 255.

storylines.color.RGB2HSV(R, G, B)[source]

Transform red, green, blue to hue, saturation, value.

Parameters:
R, G, Bfloat

Red, green, and blue values between 0 an 255.

Returns:
float

Hue with period of 360 (degrees).

float

Saturation between 0 and 1.

float

Value/brightness between 0 and 255.

storylines.color.colorize(data, cmap=None, minimum=None, maximum=None)[source]

Colorize data using colormap.

Parameters:
datalist of list

Data on two-dimensional mesh.

cmapfunction

Colormap.

minimum, maxmimumfloat

Data values corresponding to minimum and maximum of color scale.

Returns:
list of list of list

RGB image.

storylines.color.colormap(*args)[source]

Map interval [0, 1] to colors.

Colors can be defined for an arbitrary number of points in the interval. In between, colors are interpolated linearly. The color for the point None is used for NaNs and beyond the outermost points where colors have been defined.

Examples:

bluebrown = colormap( # PRB 101, 155107 (2020)
    (0, Color(0.0, 1, 255, 'PSV'), math.sqrt),
    (1, Color(5.5, 1, 255, 'PSV')),
    (None, Color(255, 255, 255, 'RGB')),
    )

AFMhot = colormap( # Gnuplot
    (0.00, Color(  0,   0,   0)),
    (0.25, Color(128,   0,   0)),
    (0.50, Color(255, 128,   0)),
    (0.75, Color(255, 255, 128)),
    (1.00, Color(255, 255, 255)),
    )