[Tex/LaTex] Plot theoretical Binomial distribution with pgfplots

pgfplotspython

I am trying to plot the theoretical binomial distribution with pgfplots but don't get the desired output:

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


\begin{python}%
import numpy as np
from scipy import special
N,p=150,.5
def f(n):
    return special.binom(N,n)*p**n*(1-p)**(N-n)
s = map(f,range(1,N))
np.savetxt("bernoulli.dat",s,fmt='%0.5f')
\end{python}%


\begin{tikzpicture}
  \begin{axis}[]
    \addplot[%
    hist={density,bins=150,data min=0,data max=150},
    fill=green,
    ]%
    table [y index=0] {bernoulli.dat};
  \end{axis}
\end{tikzpicture}

\end{document}

Output:

output

Any idea what's wrong with this?

Edit

You have to compile this one with pdflatex and --shell-escape.

bernoulli.dat looks like this:

0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00001
0.00001
0.00003
0.00005
0.00010
0.00017
0.00031
0.00052
0.00085
0.00137
0.00213
0.00324
0.00478
0.00686
0.00958
0.01302
0.01723
0.02219
0.02782
0.03396
0.04035
0.04669
0.05261
0.05773
0.06168
0.06418
0.06504
0.06418
0.06168
0.05773
0.05261
0.04669
0.04035
0.03396
0.02782
0.02219
0.01723
0.01302
0.00958
0.00686
0.00478
0.00324
0.00213
0.00137
0.00085
0.00052
0.00031
0.00017
0.00010
0.00005
0.00003
0.00001
0.00001
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000

Best Answer

Putting @John Kormylos und @cgnieders comments together I get the following solution using ybar interval instead of hist:

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


\begin{python}%
import numpy as np
from scipy import special
N,p=150,.5
def f(n):
    return special.binom(N,n)*p**n*(1-p)**(N-n)
s = zip(range(1,N),map(f,range(1,N)))
np.savetxt("bernoulli.dat",s,fmt='%0.5f')
\end{python}%


\begin{tikzpicture}
  \begin{axis}[width=10cm]
    \addplot[%
    ybar interval,
    fill=blue!30,
    draw opacity=0.5,
    line width=0.4pt,
    ]%
    table {bernoulli.dat};
  \end{axis}
\end{tikzpicture}

\end{document}

Output: output