import matplotlib.pyplot as pl
import bluebell as bb
import bluebell.plot as bbplot

np.random.seed(3816547290)
mu = np.array([1.,1.])
C = np.array([[1., 0.5], [0.5, 1.]])
std = np.sqrt(np.diag(C))
low = mu - 1.5
high = mu + 1.5
x = np.random.uniform(low=low, high=high, size=(20,2))

chi2 = np.array([xi@np.linalg.inv(C)@xi for xi in x-mu])
xx = mu + (x-mu)/np.sqrt(chi2)[:,None]
dx = xx-x

bbplot.cov_ellipse(mu, C, ec='k', fc='none', lw=1.5);

for xi, dxi in zip(x, dx):
   pl.arrow(*(xi+0.05*dxi), *(0.9*dxi),
            width=0.01, head_width=0.05,
            length_includes_head=True, fc='k', ec='k')

pl.scatter(*x.T, c=np.sqrt(chi2), s=50);
pl.scatter(*xx.T, c=np.sqrt(chi2), s=50);

pl.xlim(low[0], high[0])
pl.ylim(low[1], high[1])