1

I'm trying to modify a surface in pgfplots to get something similar to a Matlab result. The image below is what I want to achieve.

Matlab result

The code I used:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{colormap/viridis,width=10cm,compat=1.9}

\begin{document}

\begin{tikzpicture} \begin{axis}[ colormap/viridis, view={60}{30}, ] \addplot3[ surf, samples=25, domain=-3:3, ] {x^2+4*y^2}; \addlegendentry{(x^2+4y^2)} \end{axis} \end{tikzpicture}

\end{document}

Result from the code

So basically what I'm trying to do is to remove the bottom of the pgfplots surface. The ellipse is defined by -2<x<2 and -1<y<1, with center in (0,0).

Stefan Pinnow
  • 29,535
  • 2
    sounds like https://tex.stackexchange.com/questions/542616/ but with elliptic level sets there could be some pain. – Symbol 1 Sep 23 '21 at 05:17

1 Answers1

1
\documentclass[border=1 cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colormap/viridis, view={40}{50}]
\addplot3[surf, shader=faceted interp, samples=25, domain=-3:3] {x^2+4*y^2};
\addlegendentry{\(x^2+4y^2\)}
\clip[preaction={fill=white}] plot[domain=-180:180, samples=100, variable=\t] ({2*cos(\t)},{sin(\t)},4);  
\addplot3[surf, shader=faceted interp, samples=25, domain=-3:3, unbounded coords=jump] {x^2+4*y^2>4 ? x^2+4*y^2 : nan};
\end{axis}
\end{tikzpicture}
\end{document}

Surface graph with elliptic cutout

or with shader=interp

Graph with smooth surface and no grid