Remember that you want to evaluate the funcition in eleven places (0,1,…,10), not ten. Anyway, I would use samples at = {0,...,10}
to place the evaluating points at wish.
\documentclass{article}
\usepackage{pgfplots}
\pgfmathdeclarefunction{poiss}{1}{%
\pgfmathparse{(#1^x)*exp(-#1)/(x!)}%
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
mark=none,domain=0:10,samples at = {0,...,10},
axis x line*=bottom,
axis y line*=left,
enlargelimits=upper}]
\addplot {poiss(1)};
\addplot {poiss(2)};
\addplot {poiss(3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
As pointed out in the comment on the question and in another question, since this is a discrete distribution, it should really not be plotted as a line plot, but rather with the ycomb
option instead:

\documentclass{article}
\usepackage{pgfplots}
\pgfmathdeclarefunction{poiss}{1}{%
\pgfmathparse{(#1^x)*exp(-#1)/(x!)}%
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
samples at = {0,...,15},
axis x line*=bottom,
axis y line*=left,
enlargelimits=upper}]
\addplot +[ycomb] {poiss(1)};
\addplot +[ycomb] {poiss(4)};
\addplot +[ycomb] {poiss(7)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Updated version (without crossing):
A possibility with random colors, widths, directions, lengths; the image was produced using
\RandArrow
\def\Columns{10}
\RandArrow[80]

The code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\def\maxArrow{30}
\def\Columns{6}
\newcommand\randomarrow{
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\edef\R{\pdfuniformdeviate 255}
\edef\G{\pdfuniformdeviate 255}
\edef\B{\pdfuniformdeviate 255}
\xdefinecolor{mycolor}{RGB}{\R,\G,\B}
\tikz\draw[->,line width=2pt*rnd+1pt,color=mycolor]
(rnd,rnd) -- ++(rnd*360:rnd+0.2);
}
\newcommand\RandArrow[1][30]{%
\def\maxArrow{#1}
\begin{tikzpicture}
\foreach [count=\i] \val in {1,...,\maxArrow}
{
\path
let \n{row}={int(mod(\i -1, \Columns))},
\n{col}={ int( ( \i - 1 ) / (-\Columns) ) }
in
(\n{row}, \n{col}) rectangle +(1,1)
+(0.5, 0.5) node{\randomarrow};
}
\begin{pgfonlayer}{background}
\draw[orange!70!black,line width=1pt,fill=yellow!15]
(current bounding box.north west)
rectangle
(current bounding box.south east);
\end{pgfonlayer}
\end{tikzpicture}%
}
\begin{document}
\RandArrow
\def\Columns{10}
\RandArrow[80]
\end{document}
The idea to avoid crossing arrows is to have a grid and place each arrow in one of the squares of the grid.
\maxArrows
allows to specify the number of arrows (initially set to 30
).
\Columns
controls the number of rows of the grid (initially set to 6
).
\randomarrow
draws an arrow; the width, length, color and direction are chosen randomly using rnd
; the length will only be (in the worst case) 0.2cm
larger than the width of the square; this is to prevent arrows from having zero length.
The main command is \RandArrow
with an optional argument allowing to decide the number of arrows to be drawn; the default value is 30
.
As suggested by Paul Gaborit in his answer
, \pgfmathsetseed{\pdfuniformdeviate 10000000}
was used in the definition of \randomarrow
to change the seed used by the pseudo-random generator at each compilation.
Introducing some randomness in the grid gives better results:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\def\maxArrow{30}
\def\Columns{6}
\newcommand\randomarrow{
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\edef\R{\pdfuniformdeviate 255}
\edef\G{\pdfuniformdeviate 255}
\edef\B{\pdfuniformdeviate 255}
\xdefinecolor{mycolor}{RGB}{\R,\G,\B}
\tikz\draw[->,line width=2pt*rnd+1pt,color=mycolor]
(rnd,rnd) -- ++(rnd*360:rnd+0.1);
}
\newcommand\RandArrow[1][30]{%
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\def\maxArrow{#1}
\begin{tikzpicture}
\foreach [count=\i] \val in {1,...,\maxArrow}
{
\path
let \n{row}={ int(mod(\i -1, \Columns))},
\n{col}={ int( ( \i - 1 ) / (-\Columns) ) }
in
(\n{row}, \n{col}) rectangle +({random(2,3)},rand)
node[near start] {\randomarrow};
}
\begin{pgfonlayer}{background}
\draw[orange!70!black,line width=1pt,fill=yellow!15]
(current bounding box.north west)
rectangle
(current bounding box.south east);
\end{pgfonlayer}
\end{tikzpicture}%
}
\begin{document}
\RandArrow
\def\Columns{10}
\RandArrow[80]
\end{document}

Best Answer
This is a
pgfplots
/gnuplot
solution.For
\addplot gnuplot {…}
to work you need to have a working installation ofgnuplot
on your machine and have to callpdflatex
with write18 enabled (i.e.--shell-escape
or--enable-write18
).How
pgfplots
andgnuplot
interact can be studied in thepgfplots
manual in subsection 4.2.5 “Computing Coordinates With Mathematical Expressions (gnuplot)”.There are two
foreach
loops in this code. One that loops overtikzpicture
and gives you one plot per picture, the other one loops over\addplot
so that you will get one picture with nineteen plots.Edit: Apparently
gnuplot
sees/2
as an integer rather than a floating point division.The function is therefore:
Code
Animated output of the first
tikzpicture
sOutput of the second
tikzpicture