sc_colors#

Handle colors and colormaps.

Highlights:
  • Adds colormaps including 'turbo', 'parula', and 'orangeblue'

  • sc.hex2rgb()/sc.rgb2hex(): convert between different color conventions

  • sc.vectocolor(): map a list of sequential values onto a list of colors

  • sc.gridcolors(): map a list of qualitative categories onto a list of colors

Functions

sanitizecolor

Alias to matplotlib.colors.to_rgb(), but also handles numeric inputs.

shifthue

Shift the hue of the colors being fed in.

rgb2hex

A little helper function to convert e.g. [0.53, 0.74, 0.15] to a pleasing shade of green.

hex2rgb

A little helper function to convert e.g. '87bc26' to a pleasing shade of green.

rgb2hsv

Shortcut to Matplotlib's rgb_to_hsv method, accepts a color triplet or a list/array of color triplets.

hsv2rgb

Shortcut to Matplotlib's hsv_to_rgb method, accepts a color triplet or a list/array of color triplets.

vectocolor

This function converts a vector (i.e., 1D array) of N values into an Nx3 matrix of color values according to the current colormap.

arraycolors

Map an N-dimensional array of values onto the current colormap.

gridcolors

Create a qualitative "color map" by assigning points according to the maximum pairwise distance in the color cube.

midpointnorm

Alias to Matplotlib's TwoSlopeNorm.

manualcolorbar

Add a colorbar to a plot that does not support one by default.

colormapdemo

Demonstrate a color map using simulated elevation data, shown in both 2D and 3D.

alpinecolormap

This function generates a map based on ascending height.

bicolormap

This function generators a two-color map, blue for negative, red for positive changes, with grey in the middle.

parulacolormap

Create a map similar to Viridis, but brighter.

turbocolormap

NOTE: as of Matplotlib 3.4.0, this colormap is included by default, and will soon be removed from Sciris.

bandedcolormap

Map colors onto bands of hue and saturation, with lightness mapped linearly.

orangebluecolormap

Create an orange-blue colormap; most like RdYlBu but more pleasing.