John Canning

Thoughts on higher education, academic development, sustainability, languages, statistics, humanities, free software, e-learning and more

Normal distribution curve in LaTeX

Amended: 22 February 2016: There were a couple of errors in the code which I have now fixed. The previous code omitted the need for the xcolor package and the some coding items symbols (notably '\' were missing).
I have been searching the internet on how to produce a normal distribution curve in LaTeX with the standard deviations marked. I wasn't able to find exactly what I wanted, but got some good clues here. This code uses the pgfplots package. The code should work 'as is'.

Normal distribution diagram in LaTeX (Using Pgfplots package)


\documentclass
\usepackage
\usepackage
\usepackage
\usepackage
\pgfplotsset
\begin
\pgfmathdeclarefunction<\pgfmathparse<1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))>%
>
\begin
\begin[no markers, domain=0:10, samples=100,
axis lines*=left, xlabel=Standard deviations, ylabel=Frequency,,
height=6cm, width=10cm,
xtick=, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major]
\addplot [fill=cyan!20, draw=none, domain=-3:3] \closedcycle;
\addplot [fill=orange!20, draw=none, domain=-3:-2] \closedcycle;
\addplot [fill=orange!20, draw=none, domain=2:3] \closedcycle;
\addplot [fill=blue!20, draw=none, domain=-2:-1] \closedcycle;
\addplot [fill=blue!20, draw=none, domain=1:2] \closedcycle;
\addplot[] coordinates ;
\addplot[] coordinates ;
\addplot[] coordinates ;
\node[coordinate, pin=] at (axis cs: 0, 0.4)<>;
\node[coordinate, pin=] at (axis cs: 0, 0.3)<>;
\node[coordinate, pin=] at (axis cs: 0, 0.2)<>;
\node[coordinate, pin=] at (axis cs: -0.5, 0)<>;
\node[coordinate, pin=] at (axis cs: 0.5, 0)<>;
\node[coordinate, pin=] at (axis cs: 1.5, 0)<>;
\node[coordinate, pin=] at (axis cs: -1.5, 0)<>;
\node[coordinate, pin=] at (axis cs: 2.5, 0)<>;
\node[coordinate, pin=] at (axis cs: -2.5, 0)<>;
\end
\end
\end

About John Canning

I am a Senior Lecturer at the Learning and Teaching Enhancement Centre (LTEC), Kingston University London. This is my personal website where I share my own thoughts on matters relating to teaching and learning in higher education. I am also author of the online book Statistics for the Humanities. All views expressed here are my own, except where otherwise made clear. ORCHID orcid.org/0000-0002-5481-7724