# Mimick surface plot

I am trying to illustrate limits in R^2 to my students. In doing so I created the following figure in Geogebra

Where the idea is that when you approach origo along the black and purple lines you reach 0. However riding along the ridge we instead reach some height above 0. As such the red domain is not continuous.

I tried to recreate the figure above using pgfplots however the result where somewhat appalling.

I do not think that it matters but the red figure is the function

f(x,y) = x y^3 /( 3y^2 + x^6)


restricted to the unit circle. Some of the problems is that it looks like the white line in the pgfplots image goes above the ridge and breaks the illusion. Any better way of illustrating the function above than my attempt?

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view = {-35}{35}]
surf,
colormap/cool,
samples=50,
domain=0:1,
y domain=0:2*pi,
z buffer=sort
]
( {x*cos(deg(y))},
{x*sin(deg(y))},
{x*sin(deg(y))*(x*cos(deg(y)))^3/(3*(x*sin(deg(y)))^2 + (x*cos(deg(y)))^6}
);
\end{axis}
\end{tikzpicture}
\end{document}

• You can fix this by drawing the plot in pieces and on different layers, see e.g. here. Or switch to asymptote. – user121799 Apr 4 '18 at 21:33

Certainly not a complete answer, but just spelling out my comment a tiny bit.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view = {-35}{35},axis on top,ticks=none,axis lines=center,
set layers=default,xlabel={$x$}, ylabel={$y$}, zlabel={$z$},
xlabel style={anchor=south east},
ylabel style={anchor=south west},
zlabel style={anchor=south west},
xmin=-1.25,xmax=1.25,ymin=-1.25,ymax=1.25] %<-added, this also sets layers
surf,
colormap/cool,
samples=50,
domain=0:1,
y domain=0:2*pi,
on layer=axis foreground, %<-added
z buffer=sort,
]
( {x*cos(deg(y))},
{x*sin(deg(y))},
{x*sin(deg(y))*(x*cos(deg(y)))^3/(3*(x*sin(deg(y)))^2 + (x*cos(deg(y)))^6}
);
\addplot3[variable=u,color=black,domain=-1.25:-0.195,on layer=axis foreground] (u,0, 0);