Skip to content

Instantly share code, notes, and snippets.

@osdf
Created May 3, 2011 22:27
Show Gist options
  • Save osdf/954403 to your computer and use it in GitHub Desktop.
Save osdf/954403 to your computer and use it in GitHub Desktop.
Plot beta distribution, parameters a and b are provided via cmd line.
import sys
import scipy as sp
from scipy.special import gamma
import pylab
a = float(sys.argv[1])
b = float(sys.argv[2])
def pdf(a, b, x):
Z = gamma(a + b) / gamma(a) / gamma(b)
return x**(a - 1) * (1 - x)**(b - 1) * Z
x = sp.arange(0, 1.01, 0.01)
y = pdf(a, b, x)
ax = pylab.subplot(111)
ax.plot(x, y, 'r', lw=2)
ax.set_xticks([0, 0.5, 1])
ax.set_xticklabels(['0', '0.5', '1'])
ax.set_yticks([0, 1, 2, 3])
ax.set_yticklabels(['0', '1', '2', '3'])
ax.set_xlabel(r'$\theta$', fontsize=18)
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment