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 ?

  • $\begingroup$ 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 $\endgroup$
    – Michael E2
    May 24, 2019 at 19:18

1 Answer 1


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

enter image description here

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

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

Your Answer

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

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