The issues
Because PGFPlots samples points within the domain [−3,3] × [−3,3] then constructs a plot from evaluating z-coordinates, there are two unfortunate problems we encounter when trying to plot this particular surface. First, the equation z = sqrt(−x − y2 + 8) is complex on a subset of the domain, but PGFPlots cannot plot complex values. We can use unbounded coords=jump
to resolve this first problem—this tells PGFPlots to make jumps where coordinates are nan
.
The second problem is a more of a hindrance to handle. PGFPlots does not sample evenly along the lower bound of the surface, which occurs where z = 0. This will result in a series of jagged-looking spikes along the bottom of the graph when PGFPlots attempts to stitch the evaluated points into a complete graph. A workaround for this problem is to use an if-statement that sets sufficiently small values (less than 0.2) to zero, which removes some of the roughness from the bottom of the graph.
Result
Code
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{3d, calc}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xmin = -4,
xmax = 4,
ymin = -4,
ymax = 4,
axis equal image,
unbounded coords = jump
]
\addplot3[
domain = -3:3,
samples = 80,
shader = interp,
surf,
] {-x-y^2+8 < 0.2 ? 0 : sqrt(-x-y^2+8)};
\end{axis}
\end{tikzpicture}
\end{document}
To be honest, I’m not sure whether there’s a way to change PGFPlots’ sampling intervals for the second problem, but I’d be happy for feedback in the comments if this can be improved.