# How would one 3d plot the CDF of a probability mass function in Mathematica?

I have attempted to plot the Cumulative Distribution Function of a simple piecewise probability mass function, but the code:

Plot3D[CDF[p[x, y], {x, y}], {x, -3, 3}, {y, -3, 3}]


where p[x_, y_] is the function Piecewise[...]. This yields an empty plot - why is this so? Do I have to make p of probability distribution type?

• Please provide a minimal non-working example of p[x,y] Oct 30, 2019 at 23:02
• The first argument of CDF should be a distribution rather than a probability mass function or probability density function. To convert a pdf to a distribution see ProbabilityDistribution Oct 30, 2019 at 23:46
• @BobHanlon yes I realized that the ProbabilityDistribution function takes in Probability Density Function as parameter, but since I do not have the PDF and only the have the probability mass distribution on an x-y plane, I was wondering whether it would be possible to get the CDF from this? Oct 31, 2019 at 1:03
• Look at the documentation for ProbabilityDistribution again. It will take your pmf/pdf (p[x, y]) and assumptions/constraints as inputs and define the distribution that can be used as an input to CDF Oct 31, 2019 at 1:09
• Thanks for the response @BobHanlon even from reading the documentation it is still not apparent to me that the ProbabilityDistribution function takes pmf ? Would you mind pointing out where exactly this information is? Oct 31, 2019 at 1:38

Clear["Global*"];


You have a user-defined pmf (pdf in Mathematica terms), p[x, y], For example,

p[x_, y_] = Piecewise[{
{1/8, x == 0 && y == 0},
{1/4, x == 0 && y == 1},
{1/4, x == 1 && y == 0},
{3/8, x == 1 && y == 1}}];


ProbabilityDistribution is used to define the associated distribution

distXY = ProbabilityDistribution[p[x, y], {x, 0, 1, 1}, {y, 0, 1, 1}];


The distribution is used to define the CDF

CDF[distXY, {x, y}]


Plot3D[CDF[distXY, {x, y}], {x, -1, 2}, {y, -1, 2}]
`