Hi,
I would like to plot lots of error ellipses on my plot. I thought I could use
an EllipseCollection to do so, but I didn't manage to get the ellipse sizes,
expressed in data units, right (see test script attached).
When using a plain list of Ellipse's, everything looks fine:
ells = [ P.matplotlib.patches.Ellipse(xy=xyi,
width=wi, height=hi,
angle=ai,
edgecolor='b',
facecolor='b',
alpha=0.3)
for xyi,wi,hi,ai in zip(xy,w,h,a)]
for ell in ells:
ax.add_artist(ell)
But when using EllipseCollection (as explained in
http://matplotlib.sourceforge.net/examples/pylab_examples/ellipse_collection.html),
coll = P.matplotlib.collections.EllipseCollection(widths=w,
heights=h,
angles=a,
units='x',
offsets=xy,
transOffset=ax.transData,
edgecolor='r',
facecolor='r',
alpha=0.3)
ax.add_collection(coll)
the size of the ellipses (expressed in data units) appears incorrect, and
depends furthermore of the aspect ratio of the figure (try pan/zoom or resize
the interactive window).
I naively thought the two approaches should give the same result... Did I miss
something in the way to use EllipseCollections?
Cheers,
--
.~. Yannick COPIN (o:>* Doctus cum libro
/V\ Institut de physique nucleaire de Lyon (IN2P3 - France)
// \\ Tel: (33/0) 472 431 968 AIM: YnCopin ICQ: 236931013
/( )\ http://snovae.in2p3.fr/ycopin/
^`~'^
#!/usr/bin/env python
import numpy as N
import matplotlib.pyplot as P
x = N.arange(5,dtype='d') # Position
y = x / 2
w = x/3 # Width
h = x/4 # Height
a = x*10 # PA [deg]
xy = N.vstack((x,y)).T # (n,2)
ax = P.subplot(1,1,1)
# Using EllipseCollection: size is incorrect, and depends on aspect ratio
coll = P.matplotlib.collections.EllipseCollection(widths=w,
heights=h,
angles=a,
units='x',
offsets=xy,
transOffset=ax.transData,
edgecolor='r',
facecolor='r',
alpha=0.3)
ax.add_collection(coll)
# Using plain list of Ellipse's: correct behavior
ells = [ P.matplotlib.patches.Ellipse(xy=xyi,
width=wi, height=hi,
angle=ai,
edgecolor='b',
facecolor='b',
alpha=0.3)
for xyi,wi,hi,ai in zip(xy,w,h,a)]
for ell in ells:
ax.add_artist(ell)
ax.autoscale_view()
P.show()
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users