## [Matplotlib-users] More efficient way to set_clip_path for many polygons?

 [Matplotlib-users] More efficient way to set_clip_path for many polygons? From: Alexander Crosby - 2012-06-19 16:06:13 ```The code below is a stripped down version of the way i am implementing a clip operation, but it is slow and memory inefficient. Is there a way to do this without looping or just faster, perhaps with a PolygonCollection? I have code that finds the perimeter path of a triangulation like this, but it turns out that my topology is not well formed enough for it to work. Is there a hidden matplotlib method to combine or dissolve Polygons/Patches? Thanks, Alex ------------------------ import matplotlib.tri as Tri import matplotlib.patches as patches tri = Tri.Triangulation(lonn,latn,triangles=nv) for triangle in tri.triangles: p = patches.Polygon( numpy.vstack( (lonn[triangle].T,latn[triangle].T,) ).T ) m.imshow(zi, norm=CNorm, cmap=colormap, clip_path=p) ```

 [Matplotlib-users] More efficient way to set_clip_path for many polygons? From: Alexander Crosby - 2012-06-19 16:06:13 ```The code below is a stripped down version of the way i am implementing a clip operation, but it is slow and memory inefficient. Is there a way to do this without looping or just faster, perhaps with a PolygonCollection? I have code that finds the perimeter path of a triangulation like this, but it turns out that my topology is not well formed enough for it to work. Is there a hidden matplotlib method to combine or dissolve Polygons/Patches? Thanks, Alex ------------------------ import matplotlib.tri as Tri import matplotlib.patches as patches tri = Tri.Triangulation(lonn,latn,triangles=nv) for triangle in tri.triangles: p = patches.Polygon( numpy.vstack( (lonn[triangle].T,latn[triangle].T,) ).T ) m.imshow(zi, norm=CNorm, cmap=colormap, clip_path=p) ```
 Re: [Matplotlib-users] More efficient way to set_clip_path for many polygons? From: Benjamin Root - 2012-06-19 16:14:58 Attachments: Message as HTML ```On Tue, Jun 19, 2012 at 12:06 PM, Alexander Crosby wrote: > The code below is a stripped down version of the way i am implementing a > clip operation, but it is slow and memory inefficient. Is there a way to > do this without looping or just faster, perhaps with a > PolygonCollection? > > I have code that finds the perimeter path of a triangulation like this, > but it turns out that my topology is not well formed enough for it to > work. Is there a hidden matplotlib method to combine or dissolve > Polygons/Patches? > > Thanks, > Alex > > I have found the Shapely library to be 2-4 times faster in performing topology related operations out-of-the-box than my own hand-optimized utilizations of matplotlib internals (of course, combining my optimizations with shapely yielded insanely fast performance, but at a loss of generality). It would require re-working of your existing code, but if performance is the bottle-neck, shapely is the way to go. Cheers! Ben Root ```

No, thanks