1
$\begingroup$

I have to plot a function of three varaibles $F(\theta,\beta,\gamma)$ with version 10.0 and I thought to follow the first advice of this answer, so my plot is given by:

xyz = Flatten[
   Table[{i, j, k}, {i, 0, Pi, 0.1}, {j, 0, 2 Pi, 0.1}, {k, 0, Pi, 
     0.1}], 2];

f[x_, y_, z_] := Cos[x] Sin[y] Cos[z];

Graphics3D[
 Point[xyz, VertexColors -> (Hue /@ Rescale[f[##] & @@@ xyz])], 
 Axes -> True, AxesLabel -> {\[Theta], \[Beta], \[Gamma]}]

I want to add a color legend to it how can I do it?

$\endgroup$
3
$\begingroup$

The general way would be to use

Legended[
 Graphics3D[
  Point[xyz, VertexColors -> (Hue /@ Rescale[f[##] & @@@ xyz])], 
  Axes -> True, AxesLabel -> {\[Theta], \[Beta], \[Gamma]}],
 BarLegend[Hue]
 ]

Mathematica graphics

Now, you only need to scale the ticks of the legend, but I'm sure you find out yourself how this works by looking up the documentation of BarLegend.

$\endgroup$
2
  • $\begingroup$ For clarification in this answer here, does the use of Rescale serve the same purpose as ColorFunctionScaling->False? $\endgroup$ – CA Trevillian Mar 3 '20 at 13:35
  • 1
    $\begingroup$ @CATrevillian I just copied the code from the OP. If anything, then the Rescale acts like ColorFunctionScaling -> True because it rescales the whole dataset of values in the range [0,1]. However, for VertexColors you need to rescale the values yourself opposed to things like Plot that do it for you. $\endgroup$ – halirutan Mar 4 '20 at 6:59

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.