Skip to content

Instantly share code, notes, and snippets.

@erikbern

erikbern/beta.py

Created Aug 15, 2017
Embed
What would you like to do?
import matplotlib.pyplot, numpy, scipy.stats, seaborn
for i in range(50):
p, = scipy.stats.uniform.rvs(size=1)
a, b = scipy.stats.geom.rvs(p, size=2)
if a == b == 1:
continue
print(a, b)
x = numpy.linspace(0, 1, 1000)
y = scipy.stats.beta.pdf(x, a, b)
matplotlib.pyplot.figure(figsize=(7, 2))
matplotlib.pyplot.plot(x, y)
matplotlib.pyplot.fill_between(x, x*0, y, alpha=0.2)
matplotlib.pyplot.title('Beta(a=%d, b=%d)' % (a, b))
matplotlib.pyplot.xlabel('$x$')
matplotlib.pyplot.ylabel('$P(x)$')
matplotlib.pyplot.yticks([])
matplotlib.pyplot.tight_layout()
matplotlib.pyplot.savefig('%03d.png' % i, dpi=500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment