Looking at the plot below, how can I know what colours made the Hue shade?

Plot3D[Cos[x - y + x], {x, -10, 10}, {y, -10, 10}, ColorFunction -> Hue]


I want to have only the RGB or HTML color values used by Hue.

I have copied the colors from rm -rf♦'s answer:

FF0000
FF9800
CCFF00
33FF00
00FF66
00FFFF
0066FF
CB00FE
FF0099
FF0000


but with an imprecise tool; how can I have the correct colors used by Mathematica, when I use the ColorFunction -> Hue command?

• you want to use Blend – chris Oct 17 '12 at 22:49
• Could you explain the second part of your question a bit more? Note that you don't use Mathematica syntax there. – Sjoerd C. de Vries Oct 18 '12 at 6:03

Hue[x] is equivalent to Hue[x, 1, 1]. You can create a simple "table" of colors mapped to x as:

Graphics[{Hue@#, Disk[], Text[Style[ToString@#, FontColor -> Black, FontSize -> 15]]}] & /@
Range[0, 1, 0.1] // GraphicsRow


If you want the RGB values, use ColorConvert.

• The circles represent all the colors used in the plot into my question, right? So, how can i convert the circles in RGB or HTML values like 149,56,56 or 953838. – Aurelius Oct 18 '12 at 10:51
• @FormlessCloud Use ColorConvert, as I said. See Sjoerd's answer for an example. – rm -rf Oct 19 '12 at 14:50

The old package GraphicsColors had the function HSBColor[], which is exactly what was used before Hue[] became built-in. Here's a slightly tweaked reimplementation of HSBColor[]:

hue[h_?NumericQ, s_: 1, b_: 1] :=
Module[{mh = 6 Mod[h, 1], i, f, p, q, t},
{i, f} = Through[{IntegerPart, FractionalPart}[mh]];
{p, q, t} = b (1 - s {1, f, 1 - f});
RGBColor @@ {{b, t, p}, {q, b, p}, {p, b, t},
{p, q, b}, {t, p, b}, {b, p, q}}[[i + 1]]] /;
0 <= s <= 1 && 0 <= b <= 1


Compare:

Table[hue[h], {h, 0, 1, 1/6}]
{RGBColor[1, 0, 0], RGBColor[1, 1, 0], RGBColor[0, 1, 0], RGBColor[0, 1, 1],
RGBColor[0, 0, 1], RGBColor[1, 0, 1], RGBColor[1, 0, 0]}

Table[ColorConvert[Hue[h], "RGB"], {h, 0, 1, 1/6}]
{RGBColor[1., 0., 0.], RGBColor[1., 1., 0.], RGBColor[0., 1., 0.], RGBColor[0., 1., 1.],
RGBColor[0., 0., 1.], RGBColor[1., 0., 1.], RGBColor[1., 0., 0.]}


As further confirmation, you can try doing an RGB component plot for hue[], just like in Sjoerd's answer.

A much more compact implementation of hue[] goes like this:

hue[h_?NumericQ, s_: 1, b_: 1] :=
Apply[RGBColor, b (1 + s (Clip[Abs[Mod[6 h + {0, 4, 2}, 6] - 3] - 1, {0, 1}] - 1))] /;
0 <= s <= 1 && 0 <= b <= 1


It seems your question was altogether different (you really should try writing more clearly); here's a routine to produce hex values from a corresponding color:

colorToHex[col_] :=
StringJoin["#", IntegerString[Round[255 (List @@ ColorConvert[col, "RGB"])], 16, 2]]


To verify that this works, let's reproduce the hex values of the named browser-supported HTML colors:

cols = Take[First[ColorData["HTML", "Range"]], 7]
{"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque"}

colRGB = ColorData["HTML"] /@ cols
{RGBColor[0.941176, 0.972549, 1.], RGBColor[0.980392, 0.921569, 0.843137],
RGBColor[0, 1., 1.], RGBColor[0.498039, 1., 0.831373],
RGBColor[0.941176, 1., 1.], RGBColor[0.960784, 0.960784, 0.862745],
RGBColor[1., 0.894118, 0.768627]}

colorToHex /@ colRGB
{"#f0f8ff", "#faebd7", "#00ffff", "#7fffd4", "#f0ffff", "#f5f5dc", "#ffe4c4"}


Compare with the values listed here.

• Thank you for colorToHex. – g33kz0r Mar 11 '13 at 20:16
ColorConvert[Hue[0.1], "RGB"]


RGBColor[1., 0.6, 0.]

All hues, graphically:

ListLinePlot[
Table[ColorConvert[Hue[h], "RGB"] /. RGBColor -> List, {h, 0, 1, 0.01}]\[Transpose],
PlotStyle -> {Red, Green, Blue}, DataRange -> {0, 1}]


Would ColorData["HTML"] solve your problem? There are 140 colors in that list.

ColorData["HTML", "ColorRules"] // Take[#, 5] & // Column

AliceBlue->RGBColor[0.941176,0.972549,1.]
AntiqueWhite->RGBColor[0.980392,0.921569,0.843137]
Aqua->RGBColor[0,1.,1.]
Aquamarine->RGBColor[0.498039,1.,0.831373]
Azure->RGBColor[0.941176,1.,1.]

Plot3D[Cos[2 x - y], {x, -10, 10}, {y, -10, 10},
BoxRatios -> {1, 1, .1},
ColorFunction -> (Hue[#1] &)]


You can color your plot instead of Hue[#1] where #1 is x-coordinate rescaled to interval [0, 1] with the closest RGB color in ColorData["HTML"].

With[{nf = Nearest[
List @@@ ColorData["HTML", "ColorList"]]},
Plot3D[Cos[2 x - y], {x, -10, 10}, {y, -10, 10},
BoxRatios -> {1, 1, .1},
ColorFunction -> (Apply[RGBColor,
nf[ColorConvert[Hue[#1], "RGBColor"]][[1]]] &)]]


It looks the same!? It does, but it's colored with those 140 colors. See:

With[{nf = Nearest[
List @@@ ColorData["GeologicAges", "ColorList"]]},
Plot3D[Cos[2 x - y], {x, -10, 10}, {y, -10, 10},
BoxRatios -> {1, 1, .1},
ColorFunction -> (Apply[RGBColor,
nf[ColorConvert[Hue[#1], "RGBColor"]][[1]]] &)]]


You may find ColorData["HTML"] useful as well (with 216 distinct shades).

ColorData["WebSafe", "Image"]


Their name is their hex code:

ColorData["WebSafe", "ColorRules"] // Take[#, 7] & // Column

#FFFFFF->RGBColor[1.,1.,1.]
#FFFFCC->RGBColor[1.,1.,0.8]
#FFFF99->RGBColor[1.,1.,0.6]
#FFFF66->RGBColor[1.,1.,0.4]
#FFFF33->RGBColor[1.,1.,0.2]
#FFFF00->RGBColor[1.,1.,0.]
#FFCCFF->RGBColor[1.,0.8,1.]