Skip to content

Instantly share code, notes, and snippets.

@erikbern
Created August 15, 2017 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikbern/c4b3218116feb31740b7fe5b80157358 to your computer and use it in GitHub Desktop.
Save erikbern/c4b3218116feb31740b7fe5b80157358 to your computer and use it in GitHub Desktop.
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