# Plot the poisson function correctly [duplicate]

I was try to plot the Poisson distribution as a discrete graph and only found continuous graph examples like this:

Poisson distribution with tikzpicture

Formula is:

How can I plot the discrete graph?

This is how to plot the discrete Poisson function. Added ycomb to the example from the link, this makes the plot discrete and not continuous.

\documentclass{standalone}
\usepackage{pgfplots, tikz}
\pgfmathdeclarefunction{poiss}{1}{%
\pgfmathparse{(#1^x)*exp(-#1)/(x!)}%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=center,
axis y line=center,
xtick={0,2,...,19},
ytick={0.1,0.2,...,0.4},
domain = 0:18,
samples = 19,
xlabel={$k$},
ylabel={$P[k]$},
xlabel style={right},
ylabel style={above left},
ymax=0.5,
xmax=20,
x post scale=1.4
]
\addlegendentry{$\lambda = 1$}
\addlegendentry{$\lambda = 5$}
\addlegendentry{$\lambda = 9$};
\end{axis}
\end{tikzpicture}
\end{document}


• while in general a self answer is OK on the site, what is the point here? You ask a question that is too vague for anyone to answer and then immediately post the answer? Dec 12, 2015 at 20:46
• I only found this answer tex.stackexchange.com/questions/170068/… Which is incorrect, so I wanted to post a correct example how to plot the Poisson distribution Dec 13, 2015 at 9:46
• If I understand correctly, the core difference to the code you linked to is that you added the ycomb option, right? Maybe you could add that to your answer so it's clearer for others who come across the same problem?
– Jake
Dec 13, 2015 at 13:20
• The other plot is mathematical incorrect. Dec 13, 2015 at 23:35
• If that answer is incorrect, wouldn't it be better to post a correct answer to that question? And, preferably, leave a comment explaining why the accepted answer is wrong. [There is something wrong with the code in that answer, but that's just a question of a missing curly bracket.] The way you've done this, anybody looking for an answer who finds the other question will have no clue to look for yours, which is a shame if yours is right and the other wrong, as you claim.
– cfr
Dec 14, 2015 at 2:49