2
$\begingroup$

I want to replicate the color scheme colormap/hot from $\LaTeX$ PGF's package pgfplots. The color scheme colormap/hot can be found on p. 189 in the manual. It is defined by

\pgfplotsset{
colormap={hot}{color(0cm)=(blue); color(1cm)=(yellow); color(2cm)=(orange); color(3cm)=(red)}
}

The named colors are from the $\LaTeX$ package xcolor, the manual has a table of named base colors in section 4.1 and additional information, if needed.

The relevant definitions fo the used colors are from the xcolor.sty file:

\definecolorset{rgb/hsb/cmyk/gray}{}{}{
  blue,0,0,1/.66667,1,1/1,1,0,0/.11;
  yellow,0,0,1,0/1,1,0/.16667,1,1/.89;
  orange,1,.5,0/.083333,1,1/0,.5,1,0/.595;
  red,1,0,0/0,1,1/0,1,1,0/.3}

The RGB values are as expected. I think the different colors are blended in a linear fashion.

I want to have a new color scheme, which replicates the above mentioned colormap. If this is not possible, an existing color scheme can be modified. I tried this myself, but could not get a working ColorDataFunction object. With the ColorBar package I was not able to define the color scheme manually, without having to drag control points in the form.

I got as far as this:

ColorData["TemperatureMap"] // FullForm
(* ColorDataFunction["TemperatureMap","Gradients",List[0,1],Function[Blend["TemperatureMap",Slot[1]]]] *)

colfunc=ColorDataFunction["PGFhot", "Gradients", List[0, 1], Blend[Transpose[{{0, 1/3, 2/3, 1}, {Blue, Yellow, Orange, Red}}], #1] &]

But colfunc is apparently no ColorDataFunction.

In the end, I want to use the new color scheme like this:

Plot[x, {x, 0, 1}, 
  ColorFunction -> "Rainbow", 
  PlotLegends -> BarLegend[{ColorData["Rainbow"], {0, 1}}]
]
$\endgroup$
5
$\begingroup$
    colfunc = Blend[Transpose[{{0, 1/3, 2/3, 1}, {Blue, Yellow, Orange, Red}}], #]&

    Plot[x, {x, 0, 1}, ColorFunction -> colfunc, PlotLegends -> BarLegend[{colfunc, {0, 1}}]]

enter image description here

This is how to simply use a custom color scheme. If you're wanting to have it integrated into MMA in a manner similar to the built in ColorDataFunctions then this is a good question to read through.

$\endgroup$
  • $\begingroup$ Thank you. I also tried you definition of colfunc, but I did not name it and tried to use it as a pure function. But I forgot the pair of curly brackets so it would not work. $\endgroup$ – Marco Breitig Feb 12 '16 at 17:37
  • $\begingroup$ Due to the equal spacing, Blend[{Blue, Yellow, Orange, Red}, #] & will also work. $\endgroup$ – J. M. is away Mar 24 '16 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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