You can use PGFPlots for creating plots of functions (and of data files):

The binomial function isn't defined in the math engine, but you can define it yourself using the key
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
Then you can plot the function using
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,40},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
}
]
\addplot [only marks, cyan] {binom(x,40,0.2)}; \addlegendentry{$p=0.2$}
\addplot [only marks, orange] {binom(x,40,0.5)}; \addlegendentry{$p=0.5$}
\end{axis}
\end{tikzpicture}
\end{document}
To get a histogram, set ybar=0pt, bar width=1 in the axis options (make sure that you've set \pgfplotsset{compat=1.7} or newer in the preamble for this):

\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}[
samples at={0,...,40},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,40,0.2)}; \addlegendentry{$p=0.2$}
\addplot [fill=orange, fill opacity=0.5] {binom(x,40,0.5)}; \addlegendentry{$p=0.5$}
\end{axis}
\end{tikzpicture}
\end{document}
0.1s in ytick labels. – Z.H. Mar 29 '15 at 10:02babelsfrenchoption. Does anyone know how to fix this? Just use one of the codes above and add\usepackage[french]{babel}to it. Thanks! – rsa-krypto Jul 18 '19 at 00:50