2
$\begingroup$

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

Graphics3D[{Hue[1], 
Polygon[{{1/2, 0, 0}, {1, 0, 0}, {5/4, Sqrt[3]/4, 0}, {1, Sqrt[3]/2,
  0}, {1/2, Sqrt[3]/2, 0}, {1/4, Sqrt[3]/4, 0}}]}]

Mathematica graphics

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"][1] &), 
Polygon[{{1/2, 0, 0}, {1, 0, 0}, {5/4, Sqrt[3]/4, 0}, {1, Sqrt[3]/2,
  0}, {1/2, Sqrt[3]/2, 0}, {1/4, Sqrt[3]/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!

$\endgroup$
3
  • $\begingroup$ ColorFunction isn't an option of Graphics3D. You could use VertexColors. $\endgroup$ Commented Sep 16, 2015 at 14:49
  • $\begingroup$ BTW What do you mean by "lower numbers correspond to the bluer spectrum of the color gradient"? $\endgroup$ Commented Sep 16, 2015 at 14:57
  • $\begingroup$ 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 $\endgroup$
    – user238194
    Commented Sep 16, 2015 at 15:05

2 Answers 2

5
$\begingroup$

Something like this?

pol = {{1/2, 0, 0}, {1, 0, 0}, {5/4, Sqrt[3]/4, 0}, {1, Sqrt[3]/2, 0}, 
       {1/2, Sqrt[3]/2, 0}, {1/4, Sqrt[3]/4, 0}}; 
Graphics3D[{
   Polygon[ pol, 
           VertexColors -> (ColorData["TemperatureMap"] /@ Rescale[pol[[All, 1]]])
   ]}
]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – user238194
    Commented Sep 16, 2015 at 15:04
  • 1
    $\begingroup$ Well, in that case instead of the Hue[1] 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. $\endgroup$ Commented Sep 16, 2015 at 15:10
2
$\begingroup$
zmin = -1;
zmax = 1;

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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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