Take the 2-minute tour ×

I am quite new to mathematica and I am searching for a way to create a smooth colormap based on the samples given by http://colorbrewer2.org/ . Is it possible to create a interpolated function from those sample points?!

share|improve this question
By samples, do you mean color samples, i.e, color schemes? –  VLC Nov 16 '12 at 13:47
yes, as you can see on the website there are only color samples (e.g. 6 rgb values) –  MrMuh Nov 16 '12 at 13:48
Look up Blend[]... –  Ｊ. Ｍ. Nov 16 '12 at 13:54
How do you want to use your color map in Mathematica? How you incorporate your six RGB values into Blend will depend on you intended use. –  m_goldberg Nov 16 '12 at 15:30

2 Answers 2

up vote 7 down vote accepted

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

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

Mathematica graphics

share|improve this answer
Any reason for the With[] filigree (e.g. pedagogical reasons)? cf = Blend[RGBColor @@@ (dat/255), #] &; seems to work just as well... –  Ｊ. Ｍ. Nov 16 '12 at 14:29
great postings here! one last question about colorfunctions: when data values ranging from 0 ... 30 and I want to set a maximum for the colorfunction e.g. 0...20 -> all above 20 is colored with the same color (e.g.color3). is this somehow possible to achive ?! –  MrMuh Nov 16 '12 at 14:37
@J.M. that requires dat to remain defined, does it not? My intention was to create an independent function cf without any traps for beginners. Also, there should be less re-evaluation this way. –  Mr.Wizard Nov 16 '12 at 14:37
@MrMuh the function cf is automatically defined over a range of zero to one. Arguments higher than one produce the same output value, e.g.: cf /@ Range[0, 2, 1/3]. You probably want to establish your color range outside of the cf function itself, that is with the plotting function's options, etc. Perhaps you would post an additional question about this so it can be addressed more completely? –  Mr.Wizard Nov 16 '12 at 14:41
@MrMuh: you'll probably want to use Rescale[] in conjunction with Blend[], then... –  Ｊ. Ｍ. Nov 16 '12 at 14:50

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], 

enter image description here

share|improve this answer
Since the colors are equispaced, one could use the more compact Blend[{RGBColor[color1/255], RGBColor[color2/255], RGBColor[color3/255]}, x] instead. –  Ｊ. Ｍ. Nov 16 '12 at 14:02
awesome work! hm ok maybe you know how to use get the colorfunction into a ListPlot3D? –  MrMuh Nov 16 '12 at 14:22

Your Answer


