# How to highlight a 2D section of a 3D plot?

From the following 3D plot

    p1 = Plot3D[Sin[x y], {x, 0, 1}, {y, 0, 1}];
p2 = RegionPlot3D[DiscretizeRegion[
ImplicitRegion[{x - y == 0}, {x, y, z}]],
PlotStyle -> Directive[Blue, Opacity[0.3]], Mesh -> None,
MeshStyle -> Directive[LightBlue, Thin]];
Show[p1, p2, AxesLabel -> {"F", "C", "time"}]


how can one highlight a 2D slice as shown by blue dash below?

Something like:

p1 = Plot3D[Sin[x y], {x, 0, 1}, {y, 0, 1}];
p2 = RegionPlot3D[
DiscretizeRegion[ImplicitRegion[{x - y == 0}, {x, y, z}]],
PlotStyle -> Directive[Blue, Opacity[0.3]], Mesh -> None,
MeshStyle -> Directive[LightBlue, Thin]];
p3 = Graphics3D[{Dashed, Blue, Thick,
Line[{{{0.5, 0, 0}, {0.5, 0.5, Sin[0.5^2]}}, {{0.5, 0.5,
Sin[0.5^2]}, {0.5, 0.5, 1}}}]}];
Show[p1, p2, p3, AxesLabel -> {"F", "C", "time"}]


• Thanks, @Daniel Huber, you are amazing!
– Mike
Jun 16, 2023 at 19:25
• Just a minor point @Daniel Huber. In a similar situation, I have Sqrt[x y] instead of Sin[x y]. I tried this replacement of Sin by Sqrt, but it doesn't seem to work.
– Mike
Jun 16, 2023 at 19:43
• The approximation by a straight line from {0,0.5} to {0.5,0.5} is good enough for Sin, but not for Sqrt. In this case you must create an additional "ParametricPlot" for this curve. Jun 16, 2023 at 19:52

The slice corresponds to a simple relation between x and y, in this case, x=y. So you can substitute that and use Plot:

Plot[Sin[x y] /. y -> x, {x, 0, 1}]


Other slices will have different relation between x and y, and can be handled the same way.

If you prefer the horizontal axis to correspond to distance along the slice instead of along the x axis, you could use ParametericPlot instead.

To show this section on the 3D plot, use ParametricPlot3D:

Show[
Plot3D[Sin[x y], {x, 0, 1}, {y, 0, 1}],
ParametricPlot3D[Evaluate[{x, y, Sin[x y]} /. y -> x], {x, 0, 1},
PlotStyle -> Black]
]


To show x=0.5 plane up to the intersection with x=y plane, combine this with your plot:

With[{X = 0.5},
Show[
ParametricPlot3D[{X, y, Sin[X y]}, {y, 0, X}, PlotStyle -> Blue],
Graphics3D[{Blue, Thick, HalfLine[{X, X, Sin[X^2]}, {0, 0, 1}]}],
PlotRange -> All
]
]


• You can add the ParametricPlot3D to your plot. I may be confused by what slice you mean -- the plot with x=y follows the light blue slice plane of your Region plot. The dashed blue curve you show isn't on the surface. Do you mean to indicate a plane with constant x instead of x=y? If so, you could change the 1st coordinate in ParametricPlot3D to be, e.g., 0.5, or whatever value used for the dashed curve. Does that give what you want?