Adding a bar legend to a 3D plot indicating surface curvature by color
Here is another way. It gives a finer scale on the bar legend.
Legended[
ParametricPlot3D[surf[u, v], {u, -5, 5}, {v, -5, 5},
ColorFunction ->
Function[{x, y, z, u, v}, ColorData["Rainbow"] @ Rescale[gaucurv[u, v], rng]],
ColorFunctionScaling -> False,
MeshStyle -> Opacity[0.25],
Boxed -> False,
Axes -> False,
Method -> {"ShrinkWrap" -> True}],
BarLegend[{"Rainbow", {Floor[rng[[1]], .01], Ceiling[rng[[2]], .01]}}, 9]]
Replace PlotLegends -> BarLegend[{"Rainbow", rng}]
with
PlotLegends -> BarLegend[{ColorData[{"Rainbow", rng}], rng}]
or with
PlotLegends -> BarLegend[{"Rainbow", rng}, Method -> ColorFunctionScaling -> True]
to get the correct colors in the legend:
ParametricPlot3D[surf[u, v], {u, -5, 5}, {v, -5, 5},
ColorFunction -> Function[{x, y, z, u, v},
ColorData["Rainbow"]@Rescale[gaucurv[u, v], rng]],
ColorFunctionScaling -> False,
MeshStyle -> Opacity[0.25],
Axes -> False, Boxed -> False,
PlotLegends -> BarLegend[{ColorData[{"Rainbow", rng}], rng}]],
Method -> {"ShrinkWrap" -> True}]
ParametricPlot3D[surf[u, v], {u, -5, 5}, {v, -5, 5},
ColorFunction -> Function[{x, y, z, u, v},
ColorData["Rainbow"]@Rescale[gaucurv[u, v], rng]],
ColorFunctionScaling -> False,
MeshStyle -> Opacity[0.25],
Axes -> False, Boxed -> False,
PlotLegends -> BarLegend[{"Rainbow", rng}, ColorFunctionScaling -> True],
Method -> {"ShrinkWrap" -> True}]
same picture
A third approach is to move the legend outside ParametricPlot3D
using Legended
as in m_goldberg's answer:
Legended[ParametricPlot3D[surf[u, v], {u, -5, 5}, {v, -5, 5},
ColorFunction -> Function[{x, y, z, u, v},
ColorData["Rainbow"]@Rescale[gaucurv[u, v], rng]],
ColorFunctionScaling -> False, MeshStyle -> Opacity[0.25],
Axes -> False, Boxed -> False, Method -> {"ShrinkWrap" -> True}],
BarLegend[{"Rainbow", rng}]]
same picture
All three methods work both in Version 11.3 (Windows 10 6 bit) and Version 12.0 (Wolfram Cloud).