# Tikz 3D representation of the Gaussian density function

I'm trying to build the Gaussian density with equation e^(-x² - y²) in my LaTeX document, but the result doesn't really satisfy me.

Here is my source code.

 \begin{tikzpicture}
\begin{axis}[view={25}{30},mark layer=like plot]

on layer=background,
z filter/.expression={z<exp(-x^2-y^2+15) ? z : nan}]
table[row sep=crcr] {%
0 0 15\\
0 0 -15\\
};
surf,
fill opacity=0.85,
samples=55,
domain=-4:4,
y domain=-4:4,
on layer=main,
] {exp(-x^2-y^2+14)};
\end{axis}
\end{tikzpicture}


Here is a pretty satisfying image I found on the internet :

• Welcome! Please post a complete, compilable example, not a snippet. And: why did you add the circuitikz tag? I see no circuit here... Commented Oct 17, 2022 at 12:37
• I think OP is a new user, so he/she needs more time to be familiar to this forum. Some tags are edited by me. Commented Oct 17, 2022 at 15:06
• WHY does the result not satisfy you? What is your question? Commented Dec 7, 2022 at 12:42

It seems there haven't been any Gaussian density surface in this forum yet. Here I use Asymptote. You can include pdf, png image; or use asy code directly in your tex document with loaded asymptote package and include the code inside \begin{asy} and \end{asy}. Of course, you can use code on overleaf;

Surface with a rainbow pallette

// adapted from
// https://asymptote.sourceforge.io/gallery/3Dgraphs/elevation.asy
import graph3;
import palette;
currentprojection=orthographic(3,2,.4,zoom=.9);
unitsize(1cm,1cm,3cm);
defaultrender.merge=true;

real f(pair z) {return exp(-z.x*z.x-z.y*z.y);}
real a=2.5;
surface s=surface(f,(-a,-a),(a,a),25,Spline);
draw(s,mean(palette(s.map(zpart),Rainbow(40))),black);

xaxis3("$x$",-a-1,a+1,Arrow3);
yaxis3("$y$",-a-1,a+1,Arrow3);
zaxis3(Label("$z=e^{-(x^2+y^2)}$",align=E),0,1.3,Arrow3);


// Run on http://asymptote.ualberta.ca/
// modified from https://asymptote.sourceforge.io/gallery/3Dgraphs/AiryDisk.asy
unitsize(1cm,1cm,3cm);
import graph3;
currentprojection=orthographic(3,2,.4,zoom=.8);
real f(pair z) {real r=abs(z); return exp(-r^2);}
real a=3;
pen p=lightgreen;
surface s=surface(f,(-a,-a),(a,a),100,Spline);
draw(s,p);

xaxis3("$x$",Bounds,InTicks);
yaxis3("$y$",Bounds,InTicks);
zaxis3(Label(rotate(90)*"$z=e^{-(x^2+y^2)}$"),Bounds,InTicks("$%#.1f$"));


Surface with grids

// http://asymptote.ualberta.ca/
unitsize(1cm,1cm,3cm);
import graph3;
currentprojection=orthographic(3,2,.4,zoom=.9);
real f(pair z) {real r=abs(z); return exp(-r^2);}
real a=3;
pen p=yellow;
surface s=surface(f,(-a,-a),(a,a),20,Spline);
draw(s,p,meshpen=magenta);

xaxis3("$x$",-a-1,a+1,Arrow3);
yaxis3("$y$",-a-1,a+1,Arrow3);
zaxis3(Label("$z=e^{-(x^2+y^2)}$",align=E),0,1.3,Arrow3);

• Thanks, but I use Overleaf, how can I do it there ? Commented Oct 17, 2022 at 14:12
• @Fractal Have you noticed that I updated an overleaf link on the answer? Commented Dec 26, 2022 at 14:41