sciris.sc_colors.gridcolors

gridcolors(ncolors=10, limits=None, nsteps=20, asarray=False, ashex=False, reverse=False, hueshift=0, basis='default', demo=False)[source]

Create a qualitative “color map” by assigning points according to the maximum pairwise distance in the color cube. Basically, the algorithm generates n points that are maximally uniformly spaced in the [R, G, B] color cube.

By default, if there are <=9 colors, use Colorbrewer colors; if there are 10-19 colors, use Kelly’s colors; if there are >=20 colors, use uniformly spaced grid colors.

Parameters
  • ncolors (int) – the number of colors to create

  • limits (float) – how close to the edges of the cube to make colors (to avoid white and black)

  • nsteps (int) – the discretization of the color cube (e.g. 10 = 10 units per side = 1000 points total)

  • ashex (bool) – whether to return colors in hexadecimal representation

  • asarray (bool) – whether to return the colors as an array instead of as a list of tuples

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

  • hueshift (float) – whether to shift the hue (hueshift > 0 and <=1) or not (0)

  • demo (bool) – whether or not to plot the color cube itself

  • basis (str) – what basis to use – options are ‘colorbrewer’, ‘kelly’, ‘default’, or ‘none’

Example:

import pylab as pl
import sciris as sc
ncolors = 10
piedata = pl.rand(ncolors)
colors = sc.gridcolors(ncolors)
pl.pie(piedata, colors=colors)
sc.gridcolors(ncolors, demo=True)
pl.show()

Version: 2018oct30