def plot_cov_ellipse(cov, pos, nstd=<NUM_LIT:2>, ax=None, **kwargs):
def eigsorted(cov):<EOL><INDENT>vals, vecs = np.linalg.eigh(cov)<EOL>order = vals.argsort()[::-<NUM_LIT:1>]<EOL>return vals[order], vecs[:,order]<EOL><DEDENT>if ax is None:<EOL><INDENT>ax = plt.gca()<EOL><DEDENT>vals, vecs = eigsorted(cov)<EOL>theta = np.degrees(np.arctan2(*vecs[:,<NUM_LIT:0>][::-<NUM_LIT:1>]))<EOL>width, height = <NUM_LIT:2> * nstd * np.sqrt(vals)<EOL>ellip = Ellipse(xy=pos, width=width, height=height, angle=theta, **kwargs)<EOL>ax.add_artist(ellip)<EOL>return ellip<EOL>
Plots an `nstd` sigma error ellipse based on the specified covariance
matrix (`cov`). Additional keyword arguments are passed on to the
ellipse patch artist.

Parameters
----------
    cov : The 2x2 covariance matrix to base the ellipse on
    pos : The location of the center of the ellipse. Expects a 2-element
        sequence of [x0, y0].
    nstd : The radius of the ellipse in numbers of standard deviations.
        Defaults to 2 standard deviations.
    ax : The axis that the ellipse will be plotted on. Defaults to the
        current axis.
    Additional keyword arguments are pass on to the ellipse patch.

Returns
-------
    A matplotlib ellipse artist