From: Tinne De Laet <tinne.delaet@me...>  20091028 13:12:11

On Wed, Oct 28, 2009 at 9:55 AM, Tinne De Laet <tinne.delaet@...> wrote: > On Wed, Oct 28, 2009 at 9:06 AM, Eero Nevalainen > <eero.nevalainen@...> wrote: >> Hi, >> >> I need to draw error ellipses on a scatterplot. I'm guessing someone has >> done this before. >> >> I've found some examples, such as this one >> http://matplotlib.sourceforge.net/examples/pylab_examples/ellipse_rotated.html >> >> That led to the artist tutorial, and... ARGH! INFORMATION OVERFLOW! >> >> Can someone explain to me, why I suddenly have to know so much about >> matplotlib's internals to get an ellipse drawn? > > Hi, > > I just made a function to draw uncertainty ellipses defined by a > covariance matrix P: > > def plotEllipse(pos,P,edge,face): > U, s , Vh = svd(P) > orient = math.atan2(U[1,0],U[0,0]) > ellipsePlot = Ellipse(xy=pos, width=math.sqrt(s[0]), > height=math.sqrt(s[1]), angle=orient,facecolor=face, edgecolor=edge) > ax = gca() > ax.add_patch(ellipsePlot); > show() > return ellipsePlot > > To use it: ellipsePlot=plotEllipse([x,y],P,'black','0.3') > > Hope this helps, I still discoverd some problems with my plotEllipse function: 1) the angle in the ellipsePlot expects and angle in DEGREES and not in radians apparently 2) forgot a factor 2 for the width and height (it's the entire width not the `radius`) 3) removed the show() command which sometimes behaves strange (having to close the figure before continuing plotting) So a new trial: def plotEllipse(pos,P,edge,face): U, s , Vh = svd(P) orient = math.atan2(U[1,0],U[0,0])*180/pi ellipsePlot = Ellipse(xy=pos, width=2.0*math.sqrt(s[0]), height=2.0*math.sqrt(s[1]), angle=orient,facecolor=face, edgecolor=edge) ax = gca() ax.add_patch(ellipsePlot); return ellipsePlot; Good luck, Tinne 