Function Repository Resource:

ColorBrewerData

Source Notebook

Get access to the ColorBrewer's colors

Contributed by: Sander Huisman

ResourceFunction["ColorBrewerData"][name,n]

gives a sequence of n colors from the ColorBrewer scheme name.

ResourceFunction["ColorBrewerData"][name,"ColorFunction"]

gives back a continuous function.

ResourceFunction["ColorBrewerData"][]

gives the ColorBrewer color scheme categories.

ResourceFunction["ColorBrewerData"][category]

gives a list of the color schemes in category.

ResourceFunction["ColorBrewerData"][name]

gives the number of colors for the standard color scheme name.

Details and Options

ResourceFunction["ColorBrewerData"] has color schemes in three categories:
"qual"qualitative color schemes
"seq"sequential color schemes
"div"diverging color schemes
The following color schemes are available:
"qual""seq""div"
"Accent", "Dark2", "Paired", "Pastel1", "Pastel2", "Set1", "Set2", "Set3""Blues", "BuGn", "BuPu", "GnBu", "Greens", "Greys", "Oranges", 
"OrRd", "PuBu", "PuBuGn", "PuRd", "Purples", "RdPu", "Reds", "YlGn", "YlGnBu", "YlOrBr", "YlOrRd""BrBG", "PiYG", "PRGn", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", "Spectral"
For large n, for which no standard ColorBrewer scheme exists, interpolation is used.

Examples

Basic Examples (3) 

Give nine colors from ColorBrewer's color scheme "PuBuGn":

In[1]:=
ResourceFunction["ColorBrewerData"]["PuBuGn", 9]
Out[1]=

Give all the categories of ColorBrewer color schemes:

In[2]:=
ResourceFunction["ColorBrewerData"][]
Out[2]=

Give all the ColorBrewer color schemes from the category "seq":

In[3]:=
ResourceFunction["ColorBrewerData"]["seq"]
Out[3]=

Scope (2) 

Retrieve a color function based on a ColorBrewer color scheme:

In[4]:=
cf = ResourceFunction["ColorBrewerData"]["YlOrBr", "ColorFunction"];
BarLegend[{cf, {0, 1}}]
Out[4]=

Retrieve the standard number of colors for a ColorBrewer scheme:

In[5]:=
ResourceFunction["ColorBrewerData"]["BuPu"]
Out[5]=

Applications (2) 

Use a ColorBrewer scheme for a plot:

In[6]:=
cols = ResourceFunction["ColorBrewerData"]["RdBu", 4];
Plot[{x, 2 x, 3 x, 4 x}, {x, 0, 5}, PlotStyle -> cols]
Out[6]=

Use a ColorBrewer scheme for a contour plot:

In[7]:=
cf = ResourceFunction["ColorBrewerData"]["RdBu", "ColorFunction"];
ContourPlot[Cos[x] + Cos[y], {x, 0, 2 Pi}, {y, 0, 2 Pi}, ColorFunction -> cf, PlotLegends -> Automatic]
Out[7]=

Possible Issues (4) 

Unknown color schemes return $Failed:

In[8]:=
ResourceFunction["ColorBrewerData"]["Pinks"]
Out[8]=

For small n, the smallest color set is subsampled:

In[9]:=
ResourceFunction["ColorBrewerData"]["Oranges", 2]
Out[9]=
In[10]:=
ResourceFunction["ColorBrewerData"]["Oranges", 1]
Out[10]=

A color function based on a qualitative color scheme is possible, but not ideal:

In[11]:=
cf = ResourceFunction["ColorBrewerData"]["Set1", "ColorFunction"];
BarLegend[{cf, {0, 1}}]
Out[11]=

Interpolating a qualitative color scheme is possible, but not ideal:

In[12]:=
ResourceFunction["ColorBrewerData"]["Set1", 17]
Out[12]=

Neat Examples (1) 

Show all ColorBrewer categories and color schemes:

In[13]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/085930c3-2d79-4946-8b5f-676d0c8a3436"]
Out[13]=

Publisher

SHuisman

Version History

  • 1.0.0 – 09 August 2019

Related Resources

License Information