Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to plot the probability mass function of a sample of a discrete metric.

If it was continuous, I know that using pandas it would be as simple as calling:


But I'm afraid that this is not enough (or not right) for my sample. Is there a function within matplotlib, scipy, numpy, etc. that I could use for plotting it?

share|improve this question
Please explain what would be "right" for your sample. Perhaps you could post a sample figure? – whuber Aug 11 '14 at 17:02
My sample is for a discrete variable and density plots are for continuos variables. Here's what I get using the code above:… As I am dealing with a discrete sample, I don't think I should get a continuos plot. – Milena Araujo Aug 11 '14 at 17:08
But what kind of a plot do you wish to produce? What do you hope to learn from this plot or convey about the sample to other people? There are many, many different ways to construct a graphical display of a sample! – whuber Aug 11 '14 at 17:10
I want to learn about it's shape, I am trying to infer this sample's distribution (or the one that it looks like the best). I've learned that PMFs are the discrete version of PDFs, and the later helps to infer a sample's distribution. – Milena Araujo Aug 11 '14 at 17:16
Are these results ordered categories, or are they a set of discrete values on a lattice (such as counts), or something else? – Glen_b Aug 11 '14 at 17:59
up vote 7 down vote accepted

There are two parts to your question - how to display discrete data (a data visualization issue) and how to do it in Python (a "what function do I call" issue).

I will deal with the first one.

With discrete distributions, there are a number of possible ways to display data.

Leaving aside direct implementation issues for the present, I see three main competitors:

  1. the empirical cdf.

    enter image description here

  2. a sample probability function.

    enter image description here

    These are quite suitable for count data, for example.

  3. a barplot.

    enter image description here

    This is quite suitable for ordered categories. If you order the bars from largest to smallest (or in some other meaningful-to-your-needs fashion), it's also suitable for unordered categories.

There are numerous other possibilities. However, I don't think a histogram is suitable for discrete data.

As for how you do things like this in python, after you choose a display, that would probably be a good, more specific question (but probably more on topic elsewhere; worded right it might fit better on StackOverflow, but you should check their help for what's on topic. With careful phrasing it might survive here, or it might work on Superuser.

share|improve this answer
Is this "sample probability function" the same as the "probability mass function" ? They do look similar. If not, what's the difference between them ? – Milena Araujo Aug 11 '14 at 20:55
In my post "probability function" is synonymous with "probability mass function", though the term is sometimes applied to continuous random variables to refer to their density function (see here for example). The word "sample" applies to both, since you're dealing with a sample. – Glen_b Aug 11 '14 at 22:36
@Glen_b Thank you for the explanation. I have been struggling with similar kind of issue. I suppose plotting a PMF will give more insights about the data. – Sitz Blogz Apr 21 at 16:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.