I have a question about how to implement a custom colormap, such as those specified on http://www.kennethmoreland.com/color-advice/. In particular I will be talking about the 'Extended Kindlmann' map, which can be downloaded on that page under Color Tables (byte) (lets say 32 values to start with).

So, I have a colormap specified by a .csv file. It has 4 columns, the first of which specifies what interval the color belongs to, the other 3 are the RGB values. I import them as follows:

frac = Drop[Import[
    pathName <> "extended-kindlmann-table-byte-0032.csv", {"Data", 
     All, 1}], 1];
R = Drop[Import[
    pathName <> "extended-kindlmann-table-byte-0032.csv", {"Data", 
     All, 2}], 1];
G = Drop[Import[
    pathName <> "extended-kindlmann-table-byte-0032.csv", {"Data", 
     All, 3}], 1];
B = Drop[Import[
    pathName <> "extended-kindlmann-table-byte-0032.csv", {"Data", 
     All, 4}], 1];

This seems to work. The question is then how one implements a custom colormap. This was studied in this question https://stackoverflow.com/questions/5753508/custom-colorfunction-colordata-in-arrayplot-and-similar-functions/9321152#9321152 for the jet colorfunction, where I found the following code for the colormap

jet[u_?NumericQ] := Blend[
        {{0, RGBColor[0, 0, 9/16]}, {1/9, Blue}, {23/63, Cyan}, {13/21, Yellow},
         {47/63, Orange}, {55/63, Red}, {1, RGBColor[1/2, 0, 0]}}, 
                          u] /; 0 <= u <= 1

To see how this works, I plot the colorfunction

DensityPlot[x, {x, 0, 1}, {y, 0, 1},
  ColorFunction -> jet,
  ColorFunctionScaling -> False]

which looks like this enter image description here

So, I thought I could just extend this to our colormap, as follows

ExtendedKindlmann[u_?NumericQ] := 
 Blend[Table[{frac[[i]], RGBColor[R[[i]], G[[i]], B[[i]]]}, {i, 1, 
     Length[frac]}], u] /; 0 <= u <= 1

Somehow though, this does not work. Looking at the output of the code itself it seems correct, but the colormap looks nothing like what it should: enter image description here

So my question is, what is going on? Why doesn't the above work? Would you suggest a different way of implementing a colormap?

  • 3
    $\begingroup$ Did you remember to divide the RGB values by 255? $\endgroup$
    – Jason B.
    Commented Jun 14, 2016 at 19:07

2 Answers 2


You could do something like this:

colorlist = {#1, RGBColor[#2/255, #3/255, #4/255]} & @@@ (Rest@
       , "CSV"]);
extendedKindlmann = (Blend[colorlist, #] &);

(I rehosted the file since i got intermittent 404 errors from the original source). Then you can view it using the showcolorfunction defined here


Mathematica graphics


In brief: you imported the "byte" file from Moreland's site when it's the "float" file that's in the format expected by Mathematica. (If you insist on the "byte" format, then you need to divide by 255, as Jason has said in comments.)


With[{cl = {#1, RGBColor[##2]} & @@@ Rest[

     kindlmann[t_?NumericQ] := Blend[cl, t] /; 0 <= t <= 1]

LinearGradientImage[kindlmann, {600, 60}]

colormap from Kindlmann-Reinhard-Creem paper


Not the answer you're looking for? Browse other questions tagged or ask your own question.