Skip to content

Instantly share code, notes, and snippets.

@junpenglao
Created June 8, 2018 14:18
Show Gist options
  • Save junpenglao/64ff7ec228cfbf8a187b509e30848a79 to your computer and use it in GitHub Desktop.
Save junpenglao/64ff7ec228cfbf8a187b509e30848a79 to your computer and use it in GitHub Desktop.
Visualization of realization of 2D dirichlet random variable with area plot that shows uncertainty.
import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
plt.style.use('ggplot')
pmat = np.vstack([np.linspace(1, 20, 20),
np.linspace(2, 10, 20),
np.linspace(3, 5, 20)]).T
p = np.asarray([st.dirichlet.rvs(p_, 200) for p_ in pmat])
_, ax = plt.subplots(1, 1, figsize=(10, 5))
C = ['C0', 'C1', 'C2']
for j in range(200):
pvec = p[:, j, :]
pvec_ = np.hstack([np.zeros((20, 1)), np.cumsum(pvec, axis=1)])
for i in range(3):
ax.fill_between(np.arange(20),
pvec_[:, i],
pvec_[:, i+1],
alpha=.01,
facecolor=C[i]);
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment