# Plot3D modifies the shape of a plot

I have a little problem with the Plot3D function. Depending on how I define my variables, the shape of the plot is not exactly the same.

The first way I use is for instance:

Plot3D[If[Sin[xyz] > 1/2, Sin[xyz], 0] /. z -> 1, {x, -1, 1}, {y, -1, 1}]

You can see that the graph is continued which should not be the case.

And the second is:

z = 1; Plot3D[If[Sin[xyz] > 1/2, Sin[xyz], 0], {x, -1, 1}, {y, -1, 1}]

Here the graph is not continued but now I have defined a global z.

I prefer using the first way because in this case z is only defined for the plot, yet I prefer the shape of the second way. How could I have a discontinued graph but without defining a global z ?

• You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is useful for learning how to format your questions and answers. You may also find this meta Q&A helpful – Michael E2 May 24 at 19:18

You can wrap the first argument with Evaluate:

Plot3D[Evaluate[If[Sin[x y z] > 1/2, Sin[x y z], 0] /. z -> 1], {x, -1, 1}, {y, -1, 1}]


Alternatively, you can use the option Exclusions:

Plot3D[If[Sin[x y z] > 1/2, Sin[x y z], 0] /. z -> 1, {x, -1, 1}, {y, -1, 1},
Exclusions -> {Sin[x y ] == 1/2}]


same picture

• Thank you, it is working fine with Evaluate ! – Raphaël May 24 at 14:24
• @Raphaël, my pleasure. Welcome to mma.se. – kglr May 24 at 14:25