Module covellipse
source code
covellipse package Author: Joris De Ridder
Sometime people plot an "errorbox" in a 2D diagram while
they should actually plot an "error-ellipse". This package
allows to draw such an error-ellipse given the 2D covariance matrix of
your measurement. The latter also allows to take into account the
correlation between the two quantitites.
Example:
Import the required packages:
>>> from numpy import *
>>> from numpy.random import multivariate_normal
>>> from matplotlib import pylab as p
>>> from covellipse import sigmaEllipse
For the sake of this example, we make some fake data:
>>> covMatrix = array([[2.0, -0.75*sqrt(4)*sqrt(2)],[-0.75*sqrt(4)*sqrt(2), 4.0]])
>>> m = multivariate_normal([0,0],covMatrix, 3000)
Compute the 2-sigma ellipse, centered around (0,0):
>>> x,y=sigmaEllipse(0,0,covMatrix,2)
Make a plot of the data as well as the ellipse:
>>> p.scatter(m[:,0], m[:,1], s=5)
>>> p.plot(x,y,linewidth=2)
tuple of 2 arrays (dtype: float)
|
|
tuple of two float ndarrays
|
sigmaEllipse(xc,
yc,
covMatrix,
nSigma)
Return x and y value of the |nSigma|-sigma ellipse Given a covariance
matrix, and the center of the ellipse (xc,yc) |
source code
|
|
Returns x and y values of a complete ellipse
- Parameters:
xc (float) - x-coordinate of the center of the ellipse
yc (float) - y-coordinate of the center of the ellipse
a (float) - half the long axis of the ellipse
b (float) - half the small axis of the ellipse
phi (float) - angle between long axis and the x-axis (radians)
- Returns: tuple of 2 arrays (dtype: float)
- x,y: coordinate arrays of ellipse
|
Return x and y value of the |nSigma|-sigma ellipse Given a covariance
matrix, and the center of the ellipse (xc,yc)
- Parameters:
xc (float) - x-coordinate of the center of the ellipse
yc (float) - y-coordinate of the center of the ellipse
covMatrix (2x2 float nd-array) - 2D covariance matrix
nSigma (float) - the nSigma-contour of the ellipse will be returned
- Returns: tuple of two float ndarrays
- (x,y): the x and y values of the ellipse
|