Circle Collection

Hi everyone,

The code below was working for me as a charm, but since the new matlplotlib
flavor 0.98, I'm getting this error message:

AttributeError: 'CirclePolygon' object has no attribute 'get_verts' <<

Any idea?

- - - - - - - - - - - - - - - - - - -

import matplotlib
from matplotlib.patches import CirclePolygon
from matplotlib.collections import PolyCollection
import pylab

fig=pylab.figure()
ax=fig.add_subplot(111)

resolution = 50 # the number of vertices
N = 20
x = pylab.rand(N)
y = pylab.rand(N)
radii = 0.1*pylab.rand(N)
colors = 100*pylab.rand(N)
verts =
for x1,y1,r in zip(x, y, radii):
    circle = CirclePolygon((x1,y1), r, resolution)
    verts.append(circle.get_verts())
    
p = PolyCollection(verts, cmap=matplotlib.cm.jet)
p.set_array(pylab.array(colors))
ax.add_patch(p)
pylab.colorbar(p)

ax.axis('equal')
pylab.show()

···

--
View this message in context: http://www.nabble.com/Circle-Collection-tp17866685p17866685.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

You've hit one of the changed APIs in 0.98. You can see the list of changed APIs here:

http://matplotlib.svn.sourceforge.net/viewvc/*checkout*/matplotlib/trunk/matplotlib/API_CHANGES

Patches no longer store lists of vertices, they store Path objects + Affine transforms. So rather than "get_verts()", you can use the admittedly obtuse "circle.get_transform().transform(get_path().vertices)".

Note also another change is required in your script for something that probably only worked by accident before. The "ax.add_patch(p)" should be "ax.add_collection(p)", since p is a PolyCollection.

Now -- for the other developers on this list: We may want to add a .get_verts() function back to patches that does exactly what I recommend above. It won't behave identically to 0.91 since it will return a transformed copy of the vertices, but that won't matter in all cases (such as this one).

We may want to add a PatchCollection class that takes a list of patches, so users don't have to manually take patches apart like this. This is now possible because all patches are basically the same thing. This would also make it easier to use an bezier-approximated Ellipse rather than a polygonal approximated one.

Cheers,
Mike

sidimok wrote:

···

Hi everyone,

The code below was working for me as a charm, but since the new matlplotlib
flavor 0.98, I'm getting this error message:

AttributeError: 'CirclePolygon' object has no attribute 'get_verts' <<
      
Any idea?

- - - - - - - - - - - - - - - - - - -
import matplotlib from matplotlib.patches import CirclePolygon from matplotlib.collections import PolyCollection import pylab

fig=pylab.figure() ax=fig.add_subplot(111)

resolution = 50 # the number of vertices N = 20 x = pylab.rand(N) y = pylab.rand(N) radii = 0.1*pylab.rand(N) colors = 100*pylab.rand(N) verts = for x1,y1,r in zip(x, y, radii): circle = CirclePolygon((x1,y1), r, resolution) verts.append(circle.get_verts())
    p = PolyCollection(verts, cmap=matplotlib.cm.jet) p.set_array(pylab.array(colors)) ax.add_patch(p) pylab.colorbar(p)

ax.axis('equal') pylab.show()

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Hmm, we are asking each other the same question in different threads :slight_smile:

  Thread: [Matplotlib-users] Drawing filled circles (discs) | matplotlib

I committed this method.

JDH

···

On Tue, Jun 17, 2008 at 7:34 AM, Michael Droettboom <mdroe@...86...> wrote:

Now -- for the other developers on this list: We may want to add a
.get_verts() function back to patches that does exactly what I recommend
above. It won't behave identically to 0.91 since it will return a
transformed copy of the vertices, but that won't matter in all cases
(such as this one).

My e-mail has been kind of sporadic this morning... but we seem to be in agreement.

Just realised get_verts could actually be slightly better --

If we use Path.to_polygons() then any curves in the patch will get converted to line segments. Then even patches like Ellipse and Arc will work and do the expected thing. I've committed this (along with a small bugfix to to_polygons).

Cheers,
Mike

John Hunter wrote:

···

On Tue, Jun 17, 2008 at 7:34 AM, Michael Droettboom <mdroe@...86...> wrote:

Now -- for the other developers on this list: We may want to add a
.get_verts() function back to patches that does exactly what I recommend
above. It won't behave identically to 0.91 since it will return a
transformed copy of the vertices, but that won't matter in all cases
(such as this one).
    
Hmm, we are asking each other the same question in different threads :slight_smile:

  Thread: [Matplotlib-users] Drawing filled circles (discs) | matplotlib

I committed this method.

JDH
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Thank you very much indeed guys, you made my day. =)

···

--
View this message in context: http://www.nabble.com/Circle-Collection-tp17866685p17913009.html
Sent from the matplotlib - users mailing list archive at Nabble.com.