(P, level, n=100)
return pos[:n, 0], pos[:n, 1], pos[:n - 1:-1, 1]
Compute the bounds of a 2D ellipse.

    The levelset of the ellipsoid is given by
    level = x' P x. Given the coordinates of the first
    dimension, this function computes the corresponding
    lower and upper values of the second dimension and
    removes any values of x0 that are outside of the ellipse.

    Parameters
    ----------
    P : np.array
        The matrix of the ellipsoid
    level : float
        The value of the levelset
    n : int
        Number of data points

    Returns
    -------
    x : np.array
        1D array of x positions of the ellipse
    yu : np.array
        The upper bound of the ellipse
    yl : np.array
        The lower bound of the ellipse

    Notes
    -----
    This can be used as
    ```plt.fill_between(*ellipse_bounds(P, level))```
Compute the bounds of a 2D ellipse.
Compute the bounds of a 2D ellipse .
def ellipse_bounds(P, level, n=100):
    """Compute the bounds of a 2D ellipse.

    The levelset of the ellipsoid is given by
    level = x' P x. Given the coordinates of the first
    dimension, this function computes the corresponding
    lower and upper values of the second dimension and
    removes any values of x0 that are outside of the ellipse.

    Parameters
    ----------
    P : np.array
        The matrix of the ellipsoid
    level : float
        The value of the levelset
    n : int
        Number of data points

    Returns
    -------
    x : np.array
        1D array of x positions of the ellipse
    yu : np.array
        The upper bound of the ellipse
    yl : np.array
        The lower bound of the ellipse

    Notes
    -----
    This can be used as
    ```plt.fill_between(*ellipse_bounds(P, level))```
    """
    # Round up to multiple of 2
    n += n % 2

    # Principal axes of ellipsoid
    eigval, eigvec = np.linalg.eig(P)
    eigvec *= np.sqrt(level / eigval)

    # set zero angle at maximum x
    angle = np.linspace(0, 2 * np.pi, n)[:, None]
    angle += np.arctan(eigvec[0, 1] / eigvec[0, 0])

    # Compute positions
    pos = np.cos(angle) * eigvec[:, 0] + np.sin(angle) * eigvec[:, 1]
    n /= 2

    # Return x-position (symmetric) and upper/lower bounds
    return pos[:n, 0], pos[:n, 1], pos[:n - 1:-1, 1]
def ellipse_bounds ( P , level , n = 100 ) : # Round up to multiple of 2 n += n % 2 # Principal axes of ellipsoid eigval , eigvec = np . linalg . eig ( P ) eigvec *= np . sqrt ( level / eigval ) # set zero angle at maximum x angle = np . linspace ( 0 , 2 * np . pi , n ) [ : , None ] angle += np . arctan ( eigvec [ 0 , 1 ] / eigvec [ 0 , 0 ] ) # Compute positions pos = np . cos ( angle ) * eigvec [ : , 0 ] + np . sin ( angle ) * eigvec [ : , 1 ] n /= 2 # Return x-position (symmetric) and upper/lower bounds return pos [ : n , 0 ] , pos [ : n , 1 ] , pos [ : n - 1 : - 1 , 1 ]