Making a custom plotting function based on Bob Hanlon's method combining DensityPlot3D
and ContourPlot3D
:
ClearAll[densityPlot3DwithContours]
SetAttributes[densityPlot3DwContours, HoldAll]
densityPlot3DwContours[f_, r1:{_,_,_}, r2:{_,_,_}, r3:{_,_,_}, o:OptionsPattern[]] :=
Show[DensityPlot3D[f, r1, r2, r3,
Evaluate@FilterRules[{o}, Options[DensityPlot3D]]],
ContourPlot3D[f, r1, r2, r3,
PlotLegends -> Automatic,
Evaluate @ FilterRules[DeleteCases[ColorFunction -> _]@{o},
Options[ContourPlot3D]],
Contours -> {{0., Opacity[.3, Red]}},
ContourStyle -> Automatic,
Mesh -> None,
BoundaryStyle -> None,
PlotPoints -> 70]]
Examples:
densityPlot3DwContours[x y z, {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
PlotLegends -> BarLegend[Automatic, "StyledContours" -> {{0, Red}}]]

densityPlot3DwContours[x y z, {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
ColorFunction -> "Rainbow",
Contours -> Thread[{{-.2, .1}, Opacity[.3, #] & /@ {Red, Green}}],
PlotLegends ->
BarLegend[Automatic, "StyledContours" -> Thread[{{-.2, .1}, {Red, Green}}]]]
