3
$\begingroup$

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?

enter image description here

$\endgroup$

2 Answers 2

3
$\begingroup$

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"}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks, @Daniel Huber, you are amazing! $\endgroup$
    – Mike
    Commented Jun 16, 2023 at 19:25
  • $\begingroup$ 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. $\endgroup$
    – Mike
    Commented Jun 16, 2023 at 19:43
  • $\begingroup$ 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. $\endgroup$ Commented Jun 16, 2023 at 19:52
3
$\begingroup$

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}]

enter image description here

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]
 ]

enter image description here

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
  ]
 ]

enter image description here

$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$
    – tad
    Commented Jun 16, 2023 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.