5

This is an extension of my previous question concerning graphing a pair of functions using pgfplots (please see link below):

How to create a gaussian curve with pgfplot?

I am trying to use the code from the previous solution I was given to produce the following functions (with labels etc./no shading) below:

Gauss picture

However, I have been running into trouble, and getting something else. So far, this is what I have come up with in terms of code:

\begin{tikzpicture}[
every pin edge/.style={<-},
every pin/.style={fill=yellow!50,rectangle,rounded corners=3pt,font=\small}]
\begin{axis}[every axis plot post/.append style={
  mark=none,domain=-5:5,samples=50,smooth},
clip=false,
axis lines=none
]
\addplot {\gauss{-1.5}{1}};
\addplot {\gauss{1}{3}};
\addplot {\gauss{3}{3.1}};
\node[pin=70:{Most efficient: p(v) has lease MSE}] at (axis description cs:0.47,0.6) {};
\node[pin=70:{p(u) has the lease bias}] at (axis description cs:0.65,0.3) {};
\node[pin=70:{p(w) has the lease variance}] at (axis description cs:0.85,0.3) {};
\node[pin=270:{$\theta$}] at (axis description cs:0.5,0.1) {};
\draw[dashed] (axis description cs:0.5,0) -- (axis description cs:0.5,0.92);
\end{axis}
\end{tikzpicture}
ealfons1
  • 259

1 Answers1

6

Here's a possibility; this time, I used the axis cs coordinate system (I wasn't sure about the position of the theta and its arrow since the original drawing is not clear in this part):

\documentclass{article}
\usepackage{pgfplots}

\newcommand\gauss[2]{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))} 
% Gauss function, parameters mu and sigma

\begin{document}

\begin{tikzpicture}[
every pin edge/.style={<-},
every pin/.style={fill=yellow!50,rectangle,
  rounded corners=3pt,font=\footnotesize},
mylabel/.style={fill=yellow!50,rectangle,
  rounded corners=3pt,font=\footnotesize,align=center}]
\begin{axis}[every axis plot post/.append style={
  mark=none,domain=-8:20,samples=50,smooth},
clip=false,
axis lines=none,
]

\def\puxpos{1}
\def\pvxpos{2.5}
\def\pwxpos{16}

\addplot {\gauss{\puxpos}{3}};
\addplot {\gauss{\pvxpos}{1}};
\addplot {\gauss{\pwxpos}{0.75}};

\draw[dashed] (axis cs:\pvxpos,0) -- (axis cs:\pvxpos,0.4);
\draw[dashed] (axis cs:\pwxpos,0) -- (axis cs:\pwxpos,0.5);

\node[pin=270:{$\theta$}] at (axis cs:1,0.065) {};
\node[mylabel] at (axis cs:\pvxpos,0.48) (pv) {MOST EFFICIENT \\ $V$ has least MSE \\ $p(v)$};
\node[mylabel] at (axis cs:-8.4,0.09) (pu) {$U$ has \\least bias \\ $p(u)$};
\node[mylabel] at (axis cs:\pwxpos,0.62) (pw) {$W$ has \\ least variance \\ $p(w)$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128