Reputation: 1892
How can I plot discrete functions, like the Poisson distribution, in gnuplot with different parameters in the same plot without having them overlap?
For example: I plot the Poisson distribution with lambda = {1,3,5} and with boxes
in the same plot. To discretize I do set xrange [1:15]; set sample 15
so that it only plots the discrete values. This works pretty well. The only problem is, that the boxes of the three different Poisson distributions (of the three different lambdas) overlap (because they all have a value at x=1, x=2, etc). Making them transparent looks still ugly (color mixing on overlaps). So I want the function to be displayed shifted. The values of Poisson(x, lambda=1) and Poisson(x, lambda=3) and Poisson(x, lambda=5) should be calculated for x at x, but for each lambda should be displayed slightly more shifted to x than the previous lambda plot so that the all boxes don't overlap and can clearly be seen.
I hope I expressed this clear enough.
With datafiles it's easy (just add something with using $1+0.1:2
, e.g.) but how do I shift analytical functions?
Upvotes: 1
Views: 1476
Reputation: 48390
In order to plot analytical functions with special needs, which require the using
statement, one can use the pseudo filename +
. In your case, the plotting script might look as follows:
set xrange[-0.5:15.5]
set samples 16
set style data boxes
set boxwidth 0.2 absolute
set style fill solid noborder
poisson(x) = lambda**x/int(x)!*exp(-lambda)
plot for [lambda=1:5:2] '+' using ($0-(lambda-3)*0.1):(poisson($0)) title sprintf("λ = %d", lambda)
Upvotes: 1