Skip to content

Instantly share code, notes, and snippets.

@ptoche
Created September 28, 2017 17:32
Show Gist options
  • Save ptoche/81326c6811bdf4253ef309c46c356464 to your computer and use it in GitHub Desktop.
Save ptoche/81326c6811bdf4253ef309c46c356464 to your computer and use it in GitHub Desktop.
%\documentclass[border=12pt]{standalone}
\documentclass{article}
\usepackage[active,tightpage]{preview}
\usepackage{tikz}
\usetikzlibrary{calc}
\PreviewEnvironment{tikzpicture}
\usepackage{pgfplots}
\usepackage{fourier}
% Normal PDF with mean/stdev arguments
\pgfmathdeclarefunction{dnorm}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
%% Set pgfplot options
\pgfplotsset{%
every axis/.append style={% axis styles
width=4in,
height=3in,
thick,
axis lines=middle,
axis line style={
->,
shorten >=-10pt,
shorten <=-10pt,
},
xtick align=outside,
ytick align=center,
tick style={very thick},
legend pos=north east,
legend cell align={left},
legend style={font=\fontsize{8}{10}\selectfont},
}
}
\def\Picture#1{%
\begin{tikzpicture}
\begin{axis}[domain=-3.5:3.5, restrict y to domain=0:4, xmin=-3.5, xmax=3.5, ymin=0, ymax=2.1, samples=201]
\addlegendimage{empty legend}% legendentry #1
\addplot[color=blue, domain=-3.5:3.5]% legendentry #2
{dnorm(0,#1)};
\addplot[color=orange, domain=-3.5:3.5]% legendentry #3
{dnorm(0,1)};
\addlegendentry{\hspace{-.6cm}\textbf{The Normal Distribution}}
\addlegendentry{$\sigma = #1$}
\addlegendentry{$\sigma = 1$}
\end{axis}
\end{tikzpicture}
}
\begin{document}
% loop over values of the standard deviation
% explicit list so it prints without approximations
\foreach \n in {0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0}
\Picture{\n};
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment