# Plotting a PMF and CDF for rolling a dice

... trowing and dice and getting 1/6 probability for each number.

My probability mass function code is

\documentclass[pstricks, margin=2mm]{standalone}
\usepackage{pst-all}

\begin{document}
\definecolor{col}{RGB}{125, 185, 250}
\savedata{\data}[
1 0.1667
2 0.1667
3 0.1667
4 0.1667
5 0.1667
6 0.1667]

\psset{xunit=0.6cm,yunit=10cm}
\pspicture(-3,-0.1)(12,0.5)
\rput(0,0){
\listplot[
origin={-1,0},
plotstyle=LineToXAxis,
linecolor=col,
]{\data}
\psaxes[Ox=1,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(5,0.4)\uput[0](2.25,-0.09){$x$}
\rput(-0.25cm,0.25cm){\psaxes[xAxis=false,Dy=0.05,dy=0.10,Oy=0.05,tickstyle=bottom]{->}(0,0.45)}\uput[-90]{90}(-2.5,0.4){$f(X)=P(X=x)$}
}
\endpspicture
\end{document}


that give this figure:

The first problem is that the representation in the y-axis is off, by an about 0.1... I guess this has to do with the yAxis definition, but I can figure it out.

The 2nd question is how can I get a CDF for the same dice distribution with pstricks(I've seen code I can adapt with tikz, but I would like to do it on pstricks).

Thanks for any help.

use a different yunit:

 \listplot[origin={-1,0},yunit=1.667,
plotstyle=LineToXAxis,linecolor=col,]{\data}


• Thanks @user187802! What about the CDF, any easy way to do it?
– JPMD
Commented Sep 6, 2022 at 10:05
• what is cdf? .... Commented Sep 6, 2022 at 11:54
• Cumulative Distribution Function :-)
– JPMD
Commented Sep 6, 2022 at 14:38
\documentclass[margin=2mm]{standalone}
\usepackage{pst-all}

\begin{document}
\definecolor{col}{RGB}{125, 185, 250}
\savedata{\data}[
1 0.1667
2 0.1667
3 0.1667
4 0.1667
5 0.1667
6 0.1667]
\psset{xunit=1cm,yunit=5cm}
\pspicture(-2,-0.2)(6,1.1)
\listplot[yunit=1.667,
origin={-1,0},
plotstyle=LineToXAxis,
linecolor=col,
linewidth=2pt
]{\data}
\psaxes[Ox=1,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(5,0.4)\uput[0](2.25,-0.2){$x$}
\rput(-0.2cm,0.2cm){\psaxes[xAxis=false,Dy=0.05,dy=0.1,Oy=0.05,tickstyle=bottom]{->}(0,0.5)}\uput[-90]{90}(-1.5,0.55){$f(X)=\text{P}[X=x]$}
\endpspicture
%
\pspicture(-2,-0.2)(7,1.1)
{\psset{linecolor=col, linewidth=1.5pt,dotsize=0.2}%
\psline{-o}(0,0.04)(1,0.04)
\multido{\ia=1+1,\ib=2+1,\ra=0.16667+0.16667}{6}{%
\psline{*-o}(\ia,\ra)(\ib,\ra)}
\psline{*-}(6,1)(6.5,1)}
\psaxes[Ox=0,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(6,0.4)
\uput[0](2.25,-0.2){$x$}
\rput(-0.2cm,0.2cm){%
\psaxes[xAxis=false,Dy=0.10,dy=0.1,Oy=0.0,tickstyle=bottom]{-}(0,1.001)
\uput[-90]{90}(-1.5,0.9){$f(X)=\text{P}[X\le x]$}
}
\endpspicture
\end{document}


• There was indeed a smart way to do it :-) but the last open circle should not be on the plot. It should just end with a line blank.
– JPMD
Commented Sep 6, 2022 at 19:39
• So \multido{\ia=1+1,\ib=2+1,\ra=0.16667+0.16667}{5} (5 not 6). Thanks @user187802
– JPMD
Commented Sep 6, 2022 at 20:00

This is probably not the smartest way to do it, but...

\documentclass[pstricks, margin=2mm]{standalone}
\usepackage{pst-all}
\usepackage{graphicx}

\begin{document}
\definecolor{col}{RGB}{125, 185, 250}
\savedata{\data}[
1 0.1667
2 0.1667
3 0.1667
4 0.1667
5 0.1667
6 0.1667]
\psset{xunit=1cm,yunit=5cm}
\pspicture(-3,-0.2)(12.5,1.1)
\rput(-1.3,0){
\listplot[yunit=1.667,
origin={-1,0},
plotstyle=LineToXAxis,
linecolor=col,
linewidth=2pt
]{\data}
\psaxes[Ox=1,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(5,0.4)\uput[0](2.25,-0.2){$x$}
\rput(-0.2cm,0.2cm){\psaxes[xAxis=false,Dy=0.05,dy=0.1,Oy=0.05,tickstyle=bottom]{->}(0,0.5)}\uput[-90]{90}(-1.5,0.55){$f(X)=\text{P}[X=x]$}
}
\rput(6.1,0){
\psline[yunit=1,linecolor=col, linewidth=1.5pt,dotsize=0.2]{-o}(0,0.04)(1,0.04)
\psline[yunit=1.1,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(1,0.1666)(2,0.1666)
\psline[yunit=1.01,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(2,0.3333)(3,0.333)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(3,0.5)(4,0.5)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(4,0.66667)(5,0.66667)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(5,0.8333)(6,0.8333)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-}(6,1)(6.5,1)

\psaxes[Ox=0,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(6,0.4)\uput[0](2.25,-0.2){$x$}
\rput(-0.2cm,0.2cm){
\psaxes[xAxis=false,Dy=0.10,dy=0.1,Oy=0.0,tickstyle=bottom]{-}(0,1.001)\uput[-90]{90}(-1.5,0.9){$f(X)=\text{P}[X\le x]$}
}