With the help of Positioning of Pgfplot axis labels I managed to create histograms of binomial distributions. What I still need is to select some of the bars and fill them with a different color or mark them in another way in order to indicate probabilities like P(X < 4) or P(3 < X < 5).
This is what I've got so far.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}[
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[ymin=0, xmin=-0.5,axis lines=left,xlabel={$k$}, ylabel={$P(X=k)$}, x label style={at={(axis description cs:1,0.1)},anchor=north},
y label style={at={(axis description cs:-0.15,1)},rotate = -90, anchor=north}, ,
samples at={0,...,12},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2
},
ybar=0pt, bar width=1
]
\addplot [fill=lightgray, fill opacity=0.5] {binom(x,12,0.4)};
\end{axis}
\end{tikzpicture}
\end{document}
