I am trying to draw uncertainty ellipse which is the ellipse of points that are one standard deviation away from the mean. I am using this code to do it: https://stackoverflow.com/a/25022642/7448860
But, instead of an ellipse it draws a line.
I'm plotting 2 random variable (x, y), so the size of covariance matric is 2 x 2. To compute covariance matric I'm using Kalman Filter Algorithm, so I don’t need to use np.cov().
Code:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
def eigsorted(cov):
vals, vecs = np.linalg.eigh(cov)
order = vals.argsort()[::-1]
return vals[order], vecs[:,order]
x = [0]
y = [0]
cov = [[0.25, 0.5 ], [0.5, 1.]]
nstd = 1
ax = plt.subplot(111)
vals, vecs = eigsorted(cov)
theta = np.degrees(np.arctan2(*vecs[:,0][::-1]))
w, h = 2 * nstd * np.sqrt(vals)
ell = Ellipse(xy=(np.mean(x), np.mean(y)),
width=w, height=h,
angle=theta, color='black')
ell.set_facecolor('none')
ax.add_artist(ell)
plt.scatter(x, y)
plt.show()
How can I draw ellipse one standard deviation away from the mean?
I tried:
x = [0,1,0,1]
y = [0,0,1,1]