# Using color gradients in Graphics3D

I would like to use the thermometer color gradient in Graphics3D. Taking an example, I have the following:

Graphics3D[{Hue,
Polygon[{{1/2, 0, 0}, {1, 0, 0}, {5/4, Sqrt/4, 0}, {1, Sqrt/2,
0}, {1/2, Sqrt/2, 0}, {1/4, Sqrt/4, 0}}]}] which gives a red hexagon as desired. However, I would like to use the thermometer colors, so that lower numbers correspond to the bluer spectrum of the color gradient. However, when I attempt to copy the code given here: https://reference.wolfram.com/language/ref/ColorData.html using

Graphics3D[{ColorFunction -> (ColorData["TemperatureMap"] &),
Polygon[{{1/2, 0, 0}, {1, 0, 0}, {5/4, Sqrt/4, 0}, {1, Sqrt/2,
0}, {1/2, Sqrt/2, 0}, {1/4, Sqrt/4, 0}}]}]


it outputs a colorless hexagon. How should I fix this, provided I want to plot data with colors accordingly on the thermometer gradient given values in the interval [-1,1]?

Thanks!

• ColorFunction isn't an option of Graphics3D. You could use VertexColors. Sep 16, 2015 at 14:49
• BTW What do you mean by "lower numbers correspond to the bluer spectrum of the color gradient"? Sep 16, 2015 at 14:57
• As in, the temperature gradient ranges from blue to red. If I assign a higher number to a hexagon, I would like it to color the hexagon red.If I assign a lower number to the hexagon, then I would like it to be a bluer color. This is not the case for hue, which takes on a wide range of colors Sep 16, 2015 at 15:05

Something like this?

pol = {{1/2, 0, 0}, {1, 0, 0}, {5/4, Sqrt/4, 0}, {1, Sqrt/2, 0},
{1/2, Sqrt/2, 0}, {1/4, Sqrt/4, 0}};
Graphics3D[{
Polygon[ pol,
VertexColors -> (ColorData["TemperatureMap"] /@ Rescale[pol[[All, 1]]])
]}
] • Not exactly. This hexagon is one unit cell in my lattice. So say I assign a number .5 to one hexagon. Then I would like it to correspond to a specific color on the temperature gradient spectrum. Then on the next hexagon in the lattice, it might have a different number, say -.5. Then its color should be blue. Sorry, if I was not clear. So basically, I want, for each hexagon, to have a solid color representing its value. Sep 16, 2015 at 15:04
• Well, in that case instead of the Hue you used in your first example simply use ColorData["TemperatureMap"][Rescale[val, {valMin, valMax}]], with val the value you want to represent and valMin and valMax the minimum and maximum values present in your data set. Sep 16, 2015 at 15:10
zmin = -1;
zmax = 1;

Manipulate[
Row[{
Graphics3D[{
ColorData["TemperatureMap"][
(z - zmin)/(zmax - zmin)],
Polygon[{
{1/2, 0, z},
{1, 0, z},
{5/4, Sqrt/4, z},
{1, Sqrt/2, z},
{1/2, Sqrt/2, z},
{1/4, Sqrt/4, z}}]},
PlotRange -> {zmin, zmax},
ImageSize -> 300,
BoxRatios -> {1, 1, 1}],
BarLegend[{"TemperatureMap", {zmin, zmax}}]}],
{{z, (zmax+zmin)/2}, zmin, zmax, .1, Appearance -> "Labeled"}] 