📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / tikz / 3d-gaussian-distribution / 3d-gaussian-distribution.tex
132932 viewsLicense: OTHER
% Thanks to Jake for the template1% http://tex.stackexchange.com/a/31715/56452% and the help here3% http://tex.stackexchange.com/a/198793/56454\documentclass{standalone}56\usepackage{pgfplots}7\pgfplotsset{compat=1.10}89\begin{document}1011\pgfplotsset{12colormap={whitered}{color(0cm)=(white); color(1cm)=(orange!75!red)},13colormap={whiteblue}{color(0cm)=(white); color(1cm)=(blue)},14}1516\begin{tikzpicture}[17declare function={mu11=60;},18declare function={mu12=20;},19declare function={sigma11=5;},20declare function={sigma12=5;},21declare function={mu21=70;},22declare function={mu22=40;},23declare function={sigma21=5;},24declare function={sigma22=5;},25declare function={rho=0.8;},26declare function={normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));},27declare function={bivar(\ma,\sa,\mb,\sb,\rho)=281/(2*pi*\sa*\sb*\rho) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2 - (2*\rho*(x-\ma)*(y-\mb))/(\sa*\sb)))/(2*(1-\rho*\rho));}]29\begin{axis}[30width=15cm,31view={-15}{70},32enlargelimits=false,33grid=major,34domain=40:90,35y domain=0:60,36samples=60,37xlabel=$x_1$,38ylabel=$x_2$,39zlabel={$P$}40]41\addplot3 [42surf,43colormap={bluewhitered}{color(0cm)=(blue); color(0.5cm)=(white); color(1cm)=(orange!75!red)},44point meta={45(46bivar(mu11,sigma11,mu12,sigma12,rho)>47bivar(mu21,sigma21,mu22,sigma22,rho)?48bivar(mu11,sigma11,mu12,sigma12,rho):49-bivar(mu21,sigma21,mu22,sigma22,rho)50)51}52] {53max(54bivar(mu11,sigma11,mu12,sigma12,rho),55bivar(mu21,sigma21,mu22,sigma22,rho)56)};5758\draw [black!50] (axis cs:-1,0,0) -- (axis cs:4,0,0);59\draw [black!50] (axis cs:0,-1,0) -- (axis cs:0,4,0);6061\node at (axis cs:-1,1,0.18) [pin=165:$P(x_1)$] {};62\node at (axis cs:1.5,4,0.32) [pin=-15:$P(x_2)$] {};63\end{axis}64\end{tikzpicture}65\end{document}6667