Wolfram Research

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

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

Retrieve a color function based on a ColorBrewer color scheme:

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

Retrieve the standard number of colors for a ColorBrewer scheme:

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

Applications

Use a ColorBrewer scheme for a plot:

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

Use a ColorBrewer scheme for a contour plot:

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

Possible Issues

Unknown color schemes return $Failed:

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

For small n, the smallest color set is subsampled:

In[12]:=
ResourceFunction["ColorBrewerData"]["Oranges", 2]
Out[12]=
In[13]:=
ResourceFunction["ColorBrewerData"]["Oranges", 1]
Out[13]=

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

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

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

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

Neat Examples

Show all ColorBrewer categories and color schemes:

In[17]:=
Grid[{Table[
   Column[Prepend[Table[
      Column[{name, Row@ResourceFunction["ColorBrewerData"][name, 8]}]
      ,
      {name, ResourceFunction["ColorBrewerData"][cat]}
      ], Style[cat, Bold]]]
   ,
   {cat, ResourceFunction["ColorBrewerData"][]}
   ]}, Alignment -> {Center, Top}, Spacings -> {4, 0}]
Out[17]=

Resource History

Related Resources

License Information