Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw probabilistic distributions with numpy/matplotlib?

I want to draw probabilistic functions (like the binomial distribution), but i don't find a function that returns the probability for given parameters. To write it myself i need binomial coefficients (I could write that myself), for which I haven't found a function either. Is there a 'short and/or easy' to do this?
To clarify: I don't want to draw histograms, and I dont want to fit a line to one.

like image 327
Sebastian Avatar asked Mar 17 '11 12:03

Sebastian


People also ask

How do you plot probability distribution in Python?

You first create a plot object ax . Here, you can specify the number of bins in the histogram, specify the color of the histogram and specify density plot option with kde and linewidth option with hist_kws . You can also set labels for x and y axis using the xlabel and ylabel arguments.

How do you plot a PDF and cdf in Python?

MatPlotLib with Python Compute the histogram of a set of data with data and bins=10. Find the probability distribution function (pdf). Using pdf (Step 5), calculate cdf. Plot the cdf using plot() method with label "CDF".


1 Answers

scipy.stats.binom.pmf gives the probability mass function for the binomial distribution. You could compute it for a range and plot it. for example, for 10 trials, and p = 0.1, you could do

import scipy, scipy.stats
x = scipy.linspace(0,10,11)
pmf = scipy.stats.binom.pmf(x,10,0.1)
import pylab
pylab.plot(x,pmf)
like image 137
highBandWidth Avatar answered Nov 15 '22 07:11

highBandWidth