# Plot3D not plotting curve of intersection that sits as a single space curve right above the surface, leaving a "hole" on the surface

I'm trying to plot the following piecewise function. $$f(x, y) = \begin{cases} 1, & \text{if xy = 0 } \\ 0, & \text{if xy \neq 0} \end{cases}$$

This is the code I've written:

f[x_, y_] := Piecewise[{{1, x*y == 0}, {0, True}}]
Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10}]


This is the result I got:

But the plot doesn't show the lines that are "lifted" from the surface. How do I fix this?

• Plot3D[] is never going to plot any one-dimensional components by itself, so you need to do extra work like what was shown in the answers you got. (Similar considerations apply for ParametricPlot3D[] with two independent variables.) Commented Apr 10, 2023 at 8:51
• @J.M.'spersistentexhaustion Thank you for pointing that out. That helps. Commented Apr 10, 2023 at 16:38

One way is to find the parametric equations of the missing lines and plot them separately using ParametricPlot3D, then combine the plots using Show:

p1=Plot3D[Piecewise[{{1,x*y==0}, {0, True}}], {x, -10, 10}, {y, -10, 10}];
p2=ParametricPlot3D[{t,0,1},{t,-10,10}];
p3=ParametricPlot3D[{0,t,1},{t,-10,10}];
Show[p1,p2,p3]


• We set the Exclusions Style to any style to keep the exclusion parts.
f[x_, y_] := Piecewise[{{1, x*y == 0}, {0, True}}]
plot = Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10},
ExclusionsStyle ->Red,
Exclusions -> "Discontinuities"]

• Then we lift the exclusion parts to z=1.
indexs = Position[plot, GraphicsGroup];
Show[Delete[plot, indexs // Last // Most],
DeleteCases[
Delete[plot, indexs // First // Most], _Line, -1] /. {x_Real,
y_Real, z_Real} :> {x, y, 1}, Boxed -> False, Axes -> False,
PlotRange -> All]


• test another condition.
Clear["Global*"];
f[x_, y_] := Piecewise[{{1, Cos[x] + Cos[y] == 1/2}, {0, True}}]
plot = Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10},
ExclusionsStyle -> Red, Exclusions -> "Discontinuities"]
indexs = Position[plot, GraphicsGroup];
Show[Delete[plot, indexs // Last // Most],
DeleteCases[
Delete[plot, indexs // First // Most], _Line, -1] /. {x_Real,
y_Real, z_Real} :> {x, y, 1}, Boxed -> False, Axes -> False,
PlotRange -> All]


• f[x_, y_] = Piecewise[{{1, Cos[x] + Cos[y] - 1/2 == 0}, {0, True}}]; plot = Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10}, ExclusionsStyle -> None]; curves = Plot3D[1, {x, -10, 10}, {y, -10, 10}, MeshFunctions -> Function[{x, y}, Cos[x] + Cos[y] - 1/2], Mesh -> {{0}}, MeshStyle -> Red, PlotStyle -> None, BoundaryStyle -> None]; Show[plot, curves, Boxed -> False, Axes -> False] Commented Apr 10, 2023 at 1:29
 Show[Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10},
PlotRange -> 3/2, BoxRatios -> 1, Boxed -> False, Axes -> False],
Plot3D[f[0, y], {x, -10, 10}, {y, -10, 10},
PlotStyle -> None, BoundaryStyle -> None, Exclusions -> None,
MeshFunctions -> {# #2 &}, Mesh -> {{0}},
MeshStyle -> Directive[Red, Thick]]]
`