1

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.

Thanks in advance. :)

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

            \addplot3 [draw=none, mark=*, mark size=2,
                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\\
                };
            \addplot3 [
                surf,
                shader=faceted,
                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 :

enter image description here

3
  • 2
    Welcome! Please post a complete, compilable example, not a snippet. And: why did you add the circuitikz tag? I see no circuit here...
    – Rmano
    Commented Oct 17, 2022 at 12:37
  • 1
    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.
    – Black Mild
    Commented Oct 17, 2022 at 15:06
  • 1
    WHY does the result not satisfy you? What is your question? Commented Dec 7, 2022 at 12:42

1 Answer 1

9

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;
https://www.overleaf.com/read/fhdzfgcvdrvq

Surface with a rainbow pallette

enter image description here

// 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);

enter image description here

// 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

enter image description here

// 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);
2
  • Thanks, but I use Overleaf, how can I do it there ?
    – Fractal
    Commented Oct 17, 2022 at 14:12
  • @Fractal Have you noticed that I updated an overleaf link on the answer?
    – Black Mild
    Commented Dec 26, 2022 at 14:41

You must log in to answer this question.

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