1

The plot of this specific elliptic paraboloid, sqrt(-x-y^2+8) comes out looking like this. I've tried parameterizing the surface, writing the equation in different forms, and messed around with the domain. The error I get most of the time is something about the z axis and having a mismatched number of rows and cols. Can someone help me by figuring out to make the surface smooth and well just not look like this? enter image description here

\usepackage{pgfplots}
    \usetikzlibrary{3d, calc}
    \pgfplotsset{compat=1.18}
\usepackage{tikz-3dplot}

    
\begin{document}

\begin{tikzpicture}
    \begin{axis}[axis lines=center]
        \addplot3[domain=-3:3, y domain=-3:3, samples=10, surf, shader=interp] {sqrt(-x-y^2+8)};
    \end{axis}
\end{tikzpicture}

\end{document}
1
  • 3
    Welcome! Please can you add a class so this can be compiled?
    – cfr
    Commented Oct 2, 2023 at 2:10

2 Answers 2

2

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

A paraboloid that opens up along the negative x-axis is showed on a graph for positive values of z. This essentially shows half of the paraboloid.

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.

2
  • Hey, just want to thank you @gz839918 for answering my question. Obviously, adding the < 0.2 ? 0 argument will make some parts outside the "real" (complex) domain of the function show a flat surface rather than being empty. Is there any way to eliminate that or is it not possible?
    – tangulo
    Commented Oct 2, 2023 at 16:18
  • @tangula I'm glad it helped! I'm not sure about the answer to your question, but it may be possible to perform a custom sample of points, by using a for-loop to sample points on z = 0 then passing all evaluated points with \addplot3 coordinates. I wouldn't know for sure until somebody tries it, though...
    – gz839918
    Commented Oct 3, 2023 at 1:21
0
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
%axis lines=center,
]
\addplot3[
surf, shader=faceted interp, line join=round,
%z buffer=sort,
domain=-3:3, y domain=-3:3,
samples=30,
unbounded coords=jump,
] {sqrt(-x-y^2+8)};
\end{axis}
\end{tikzpicture}
\end{document}

Surface plot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .