# [pstricks] plotting a piecewise constant function (step function)

Herbert Voss Herbert.Voss at FU-Berlin.DE
Thu Oct 21 11:52:01 CEST 2010

Am 21.10.2010 09:52, schrieb Leon Free:

> I want to plot the binomial (n,p) cumulative distribution function (cdf)
> which is a right continuous function with jumps at each integer between
> 0 and n (or I want to plot any such function). I call this function
> cdf(x) with x begin any real number.
>
> I managed to get the graph I want for this function relying heavily on
> FP commands provided by the fp.sty package. Here is my code :

everything kann be done more easily on PostScript side. However,
with the pst-func.tex from http://texnik.dante.de/tex/generic/ you can also
use the \psGaussI (see attched figure, created with the commented
two lines in the example)

\documentclass{article}

\usepackage{pst-func}
\makeatletter
\@namedef{psds at dotline}{\pst at gdot{ 0 0 DS \tx at SD 0 0 moveto 12 0 lineto
stroke}}
\makeatother

\begin{document}

\begin{psgraph}[Dy=0.2,Dx=2](0,0)(10,1.1){7cm}{5cm}
%  \rput[lb](2,0){\psGaussI[xunit=2.72,plotpoints=11,
%     plotstyle=dots,dotstyle=dotline,linecolor=red]{-1}{3}}%
\psline[linecolor=red](-1,0)(0,0)    % draw 1rst step of CDF
\psplot[plotpoints=10,plotstyle=dots,
dotstyle=dotline,linecolor=red]{0}{9}%
[/N 10 def    % predefined values
/p 0.3 def
/q 1 p sub def
/bc 1 def
/cdf q N exp def
]{% x value is on stack
/M N x1 sub def
/BC bc N x sub mul x 1 add div def
/ps BC Euler x1 p ln mul exp mul Euler M q ln mul exp mul def
/bc BC def
/cdf CDF def
cdf
}
\end{psgraph}

\end{document}

Herbert

-------------- next part --------------
A non-text attachment was scrubbed...
Name: x.png
Type: image/png
Size: 2640 bytes
Desc: not available