# Adding color legend to a 4d plot

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?

The general way would be to use

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

• For clarification in this answer here, does the use of Rescale serve the same purpose as ColorFunctionScaling->False? Mar 3, 2020 at 13:35
• @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. Mar 4, 2020 at 6:59