vectocolor#

vectocolor(vector, cmap=None, asarray=True, reverse=False, minval=None, maxval=None, midpoint=None, nancolor=None)[source]#

This function converts a vector (i.e., 1D array) of N values into an Nx3 matrix of color values according to the current colormap. It automatically scales the vector to provide maximum dynamic range for the color map.

Note: see sc.arraycolors() for multidimensional input.

Parameters:
  • vector (array) – Input vector (or list, it’s converted to an array)

  • cmap (str) – is the colormap (default: current)

  • asarray (bool) – whether to return as an array (otherwise, a list of tuples)

  • reverse (bool) – whether to reverse the list of colors

  • minval (float) – the minimum value to use

  • maxval (float) – the maximum value to use

  • midpoint (float) – the midpoint value to use

  • nancolor (color) – if supplied, use this color for NaN entries

Returns:

Nx4 array of RGB-alpha color values

Return type:

colors (array)

Example:

n = 1000
x = np.random.randn(n,1);
y = np.random.randn(n,1);
c = sc.vectocolor(y);
plt.scatter(x, y, c=c, s=50)
New in version 1.2.0: midpoint argument.
New in version 2.1.0: nancolor argument and remove nans by default
New in version 3.0.0: correct “midpoint” argument