Function Repository Resource:

SampleColors

Source Notebook

Sample colors from named color schemes

Contributed by: Michael Sollami

ResourceFunction["SampleColors"][k]

gives k unique colors evenly sampled based on Hue.

ResourceFunction["SampleColors"][scheme,k]

gives k colors evenly sampled from the named scheme.

Details and Options

For any scheme in the "Named" or "Indexed" collections, ResourceFunction["SampleColors"] simply uses the resource function Equisample to sample from ColorData[scheme,"ColorList"].
To sample more colors than a scheme contains, ResourceFunction["SampleColors"] has the Boolean option "Interpolation", which defaults to False.
ResourceFunction["SampleColors"] autocorrects misspellings for named schemes.

Examples

Basic Examples (3) 

Get a list of n reasonably chosen colors:

In[1]:=
ResourceFunction["SampleColors"] /@ Range[6] // Grid
Out[1]=

Sample colors from a named scheme (correcting for misspellings):

In[2]:=
ResourceFunction["SampleColors"]["solrcolors", 10]
Out[2]=

Make discrete palettes from random color gradients:

In[3]:=
Labeled[Row@ResourceFunction["SampleColors"][#, 30], Text@#] & /@ RandomSample[ColorData["Gradients"], 4] // Column
Out[3]=

Scope (2) 

Sample colors from the "Physical" collection:

In[4]:=
ResourceFunction["SampleColors"][#, 20] & /@ ColorData["Physical"]
Out[4]=

Sample colors from the "ThemeGradients" collection:

In[5]:=
Row@ResourceFunction["SampleColors"][#, 20] & /@ RandomSample[ColorData["ThemeGradients"], 4] // Column
Out[5]=

Options (1) 

To sample more colors than a scheme contains, use the option "Interpolation"True:

In[6]:=
Length@ResourceFunction["SampleColors"][22, 30] == Length@ColorData[22, "ColorList"]
Out[6]=
In[7]:=
ResourceFunction["SampleColors"][22, 30, "Interpolation" -> True]
Out[7]=

Possible Issues (2) 

For "Named" and "Indexed" color schemes, the "ColorList" property is not always sorted:

In[8]:=
ResourceFunction["SampleColors"][#, 10] & /@ ColorData["Named"]
Out[8]=

Note that for the finite "Indexed" color schemes there is a limit to the number of colors you can sample, unless you explicitly interpolate between them:

In[9]:=
ResourceFunction["SampleColors"][98, 100]
Out[9]=
In[10]:=
ResourceFunction["SampleColors"][98, 100, "Interpolation" -> True]
Out[10]=

Publisher

Michael Sollami

Version History

  • 2.0.0 – 26 February 2020
  • 1.0.0 – 07 February 2020

Related Resources

License Information