3

I am trying to get these plots:

enter image description here

and

enter image description here

Code:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}
\begin{axis}[
  no markers, domain=0:10, samples=100,
  axis lines*=left, xlabel=$score$, ylabel=$freq$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=5cm, width=12cm,
  xtick=\empty, 
  ytick=\empty,
  enlargelimits=false, 
  clip=false, 
  axis on top,
  grid = major
  ]
  \addplot [fill=blue!50,very thick,cyan!40!black] {gauss(6.5,1)} \closedcycle;

\end{axis}

\end{tikzpicture}
\end{document}

I would like some help to add the annotations and 2nd curves on each plots. Thanks for your help and time.

  • One way is to use \pgfplotsextra. Another is to define named coordinates inside the axis environment, but not use them until after \end{axis}. Also (rel axis cs: x,y) coordinates. – John Kormylo Sep 15 '16 at 4:55
2

I would use node for the labels and drawing and scope for the second plot:

\documentclass[preview]{standalone}
\usepackage{pgfplots}
\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}
\begin{axis}[
  no markers, domain=0:10, samples=100,
  axis lines=left, xlabel=$score$, ylabel=$freq$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=5cm, width=12cm,
  xtick=\empty, 
  ytick=\empty,
  enlargelimits=false, 
  clip=false, 
  axis on top,
  grid = major
  ]
  \addplot [fill=blue!50,very thick,cyan!40!black] {gauss(6.5,1)} \closedcycle;
  \node[align=center,anchor=south] at (axis cs: 6.5, 0.4){client\\scores};
  \node[align=center,anchor=north] at (axis cs: 6.5, 0){client\\mean};
  \draw[dashed] (axis cs: 6.5, 0.4) -- (axis cs: 6.5, 0);
\end{axis}

\begin{scope}[xshift=15cm]
\begin{axis}[axis lines=left,height=5cm, width=12cm,]
  \addplot coordinates{(0,0)(1,1)}; % dummy plot
\end{axis}
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

You may wanna use a function to calculate the density at the mean value rather than the hard coded 0.4 I used.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.