7

In draw-a-bivariate-normal-distribution-in-tikz, the bivariate normal distribution was plotted on the x-y plane. Is it possible to plot this on the x-z plane/y-z plane?

1 Answer 1

12

Sure. You can use the syntax \addplot3 ({x expr}, {y expr}, {z expr}); for this:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\begin{document}

\pgfplotsset{
colormap={whitered}{color(0cm)=(white); color(1cm)=(orange!75!red)}
}

\begin{tikzpicture}[
    declare function={mu1=1;},
    declare function={mu2=2;},
    declare function={sigma1=0.5;},
    declare function={sigma2=1;},
    declare function={normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));},
    declare function={bivar(\ma,\sa,\mb,\sb)=
        1/(2*pi*\sa*\sb) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2))/2;}]
\begin{axis}[
    colormap name=whitered,
    width=15cm,
    view={45}{35},
    enlargelimits=false,
    grid=major,
    domain=-1:4,
    y domain=-1:4,
    samples=26,
    z buffer=sort,
    unit vector ratio=10 1 1,
    xmin=0, xmax=0.2,
    ymin=-1, ymax=4
]
\addplot3 [surf,point meta=x] ({bivar(mu1,sigma1,mu2,sigma2)},x,y);
\end{axis}
\end{tikzpicture}
\end{document}
1
  • 1
    @Kuti Thanks are better conveyed by clicking the green tick button below the vote count on top left of the answer.
    – user11232
    Commented Jul 18, 2013 at 0:34

You must log in to answer this question.

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