Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When doing

Plot3D[Max[p^2-q^2,0],{p,0,1},{q,-1,1},PlotStyle->White]

the result looks like this (with Mathematica 8.0.0.0):

enter image description here

As you can easily see, at the "kink" where the function starts going above 0, Mathematica leaves a gap in the surface.

Why does it do that, and more importantly, what can I do about it?

share|improve this question
    
Increasing the number of PlotPoints seems to reduce the gap. –  b.gatessucks Apr 27 '12 at 10:30
    
@b.gatessucks: True, but it also increases the memory needed, and doesn't really close the gap. And I've got other cases (with more complicated functions) where the gap gets much larger than in this example. Increasing the number of points isn't really practical in those cases. –  celtschk Apr 27 '12 at 10:37
add comment

1 Answer 1

up vote 13 down vote accepted

The reason for this is automatic exclusion detection:

Here the discontinuity in the derivative is ugly:

Plot3D[Max[p^2 - q^2, 0], {p, 0, 1}, {q, -1, 1}, 
 Exclusions -> None]

Mathematica graphics

We can get Mathematica to auto-detect it, and compute the contours precisely, making the plot smooth around the discontinuity:

Plot3D[Max[p^2 - q^2, 0], {p, 0, 1}, {q, -1, 1}, 
 Exclusions -> Automatic]

Mathematica graphics

The side effect is a gap, as you noticed. Often one would prefer this gap to be filled with the same style as the plot. It can be accomplished by setting ExclusionsStyle, like this:

Plot3D[Max[p^2 - q^2, 0], {p, 0, 1}, {q, -1, 1}, 
 Exclusions -> Automatic, ExclusionsStyle -> Automatic]

Mathematica graphics

EDIT: As @celtschk notes, mesh lines or contour lines are not drawn inside the excluded region. This is very visible for large exclusions and can be prevented by forbidding exclusions with Exclusions -> None. Then the plot can be made smoother by increasing MaxRecursion and PlotPoints. Here's an example:

Plot3D[UnitStep[y], {x, -1, 1}, {y, -1, 1}, Exclusions -> None, MaxRecursion -> 5]

Mathematica graphics

share|improve this answer
    
Thank you, that gives exactly what I want. –  celtschk Apr 27 '12 at 10:43
    
Correction: Almost exactly: The grid lines are not drawn in the filled gap, which gets very visible for large gaps. –  celtschk Apr 27 '12 at 10:46
    
@celtschk You mean the mesh, right? (Mesh). That's true, the workaround would be Exclusions -> None and increasing MaxRecursion and PlotPloints manually until you get the right result. (I.e. the same thing you did.) –  Szabolcs Apr 27 '12 at 10:47
    
Yeah, I meant the mesh. Exclusions->None plus sufficiently high MaxRecursion indeed did the trick. Thank you again. –  celtschk Apr 27 '12 at 11:02
    
@celtschk The refinement in Mma's adaptive plotting is based on the curvature, so it'll converge fast around a discontinuity of the derivative (where the curvature is infinite). MaxRecursion just controls the number of allowed recursive refinement steps. –  Szabolcs Apr 27 '12 at 11:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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