Created
March 27, 2022 15:23
-
-
Save sauravrt/b2d14af6453d6b28703b60d2136ec55b to your computer and use it in GitHub Desktop.
Plot 2-sigma ellipse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_twosigma(pos, S, ax, color='g'): | |
"""Plot 2-sigma ellipse | |
Parameters | |
---------- | |
pos : tuple of length 2 | |
Center of the 2-sigma ellipse | |
S : numpy.ndarray of size 2x2 | |
Position covariance | |
ax : matplotlib.axes | |
Axes handle where the ellipse will be drawn | |
color : str, optional | |
Ellipse color, by default 'g' | |
Returns | |
------- | |
matplotlib.axes | |
Axes where the ellipse was drawn | |
""" | |
x = np.linspace(0, 2*np.pi, 360) | |
uv = np.array([np.cos(x), np.sin(x)]) # unit vector rotating 360deg | |
v2sigma = 2*np.linalg.cholesky(S)@uv | |
ax.plot(v2sigma[0, :] + pos[0], | |
v2sigma[1, :] + pos[1], | |
lw=1, color=color, alpha=0.5) | |
return ax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment