Define a color function based on color samples obtained from ColorBrewer

I enter RGB values in a matrix using Ctrl+, and Ctrl+Enter (tutorial):

Mathematica graphics

{{237, 248, 177}, {127, 205, 187}, {44, 127, 184}}

Then create a color function cf:

With[{rgb = RGBColor @@@ (dat/255)},
 cf = Blend[rgb, #] &;
]

And use it:

ArrayPlot[{Range@10}, ColorFunction -> cf]

Mathematica graphics

ListPlot3D[
 Table[Sin[j^2 + i], {i, 0, Pi, Pi/5}, {j, 0, Pi, Pi/5}],
 Mesh -> None,
 InterpolationOrder -> 0,
 ColorFunction -> cf
]

Mathematica graphics


If these are the RGB values of the color scheme:

color1 = {229, 245, 249};
color2 = {153, 216, 201};
color3 = {44, 162, 95};

you can blend them in this way:

Graphics[Table[{Blend[{{0, RGBColor[color1/255]}, {.5, 
 RGBColor[color2/255]}, {1, RGBColor[color3/255]}}, x], 
 Disk[{8 x, 0}]}, {x, 0, 1, 1/8}]]

enter image description here


Here's how to make all the color schemes in ColorBrewer available in Mathematica:

ColorBrewer =
    Association /@ Association[Import["http://colorbrewer2.org/export/colorbrewer.json"] /.
    {s_String /; StringMatchQ[s, NumberString] :> FromDigits[s], 
     s_String /; StringMatchQ[s, "rgb(*)"] :> Interpreter["Color"][s]} /. 
    v_ /; VectorQ[v, ColorQ] :> With[{cols = v}, Blend[cols, #] &]];

Thus, one can now retrieve the color schemes in Wizard's and VLC's answers like so:

{ColorBrewer["YlGnBu", 3], ColorBrewer["BuGn", 3]}

example

Tags:

Color

Plotting