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]
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]
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]
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]
PlotPoints
seems to reduce the gap. $\endgroup$