Revision: 6113
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6113&view=rev
Author:   efiring
Date:     2008-09-19 00:30:54 +0000 (Fri, 19 Sep 2008)

Log Message:
-----------
Added an EllipseCollection class to collections.py

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/collections.py

Added Paths:
-----------
    trunk/matplotlib/examples/pylab_examples/ellipse_collection.py

Added: trunk/matplotlib/examples/pylab_examples/ellipse_collection.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/ellipse_collection.py              
                (rev 0)
+++ trunk/matplotlib/examples/pylab_examples/ellipse_collection.py      
2008-09-19 00:30:54 UTC (rev 6113)
@@ -0,0 +1,34 @@
+import matplotlib.pyplot as plt
+import numpy as np
+from matplotlib.collections import EllipseCollection
+
+x = np.arange(10)
+y = np.arange(15)
+X, Y = np.meshgrid(x, y)
+
+XY = np.hstack((X.ravel()[:,np.newaxis], Y.ravel()[:,np.newaxis]))
+
+ww = X/10.0
+hh = Y/15.0
+aa = X*9
+
+
+ax = plt.subplot(1,1,1)
+
+ec = EllipseCollection(
+                        ww,
+                        hh,
+                        aa,
+                        units='x',
+                        offsets=XY,
+                        transOffset=ax.transData)
+ec.set_array((X+Y).ravel())
+ax.add_collection(ec)
+ax.autoscale_view()
+ax.set_xlabel('X')
+ax.set_ylabel('y')
+cbar = plt.colorbar(ec)
+cbar.set_label('X+Y')
+plt.show()
+
+

Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py      2008-09-18 23:36:43 UTC 
(rev 6112)
+++ trunk/matplotlib/lib/matplotlib/collections.py      2008-09-19 00:30:54 UTC 
(rev 6113)
@@ -10,7 +10,7 @@
 """
 import copy, math, warnings
 import numpy as np
-import numpy.ma as ma
+from numpy import ma
 import matplotlib as mpl
 import matplotlib.cbook as cbook
 import matplotlib.colors as _colors # avoid conflict with kwarg
@@ -878,7 +878,7 @@
     """
     A collection of circles, drawn using splines.
     """
-    def __init__(self, sizes):
+    def __init__(self, sizes, **kwargs):
         """
         *sizes*
             Gives the area of the circle in points^2
@@ -900,7 +900,93 @@
             for x in self._sizes]
         return Collection.draw(self, renderer)
 
+    def get_paths(self):
+        return self._paths
 
+class EllipseCollection(Collection):
+    """
+    A collection of ellipses, drawn using splines.
+    """
+    def __init__(self, widths, heights, angles, units='points', **kwargs):
+        """
+        *widths*: sequence
+            half-lengths of first axes (e.g., semi-major axis lengths)
+
+        *heights*: sequence
+            half-lengths of second axes
+
+        *angles*: sequence
+            angles of first axes, degrees CCW from the X-axis
+
+        *units*: ['points' | 'inches' | 'dots' | 'width' | 'height' | 'x' | 
'y']
+            units in which majors and minors are given; 'width' and 'height'
+            refer to the dimensions of the axes, while 'x' and 'y'
+            refer to the *offsets* data units.
+
+        Additional kwargs inherited from the base :class:`Collection`:
+
+        %(Collection)s
+        """
+        Collection.__init__(self,**kwargs)
+        self._widths = np.asarray(widths).ravel()
+        self._heights = np.asarray(heights).ravel()
+        self._angles = np.asarray(angles).ravel() *(np.pi/180.0)
+        self._units = units
+        self.set_transform(transforms.IdentityTransform())
+        self._transforms = []
+        self._paths = [mpath.Path.unit_circle()]
+        self._initialized = False
+
+
+    __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
+
+    def _init(self):
+        def on_dpi_change(fig):
+            self._transforms = []
+        self.figure.callbacks.connect('dpi_changed', on_dpi_change)
+        self._initialized = True
+
+    def set_transforms(self):
+        if not self._initialized:
+            self._init()
+        self._transforms = []
+        ax = self.axes
+        fig = self.figure
+        if self._units in ('x', 'y'):
+            if self._units == 'x':
+                dx0 = ax.viewLim.width
+                dx1 = ax.bbox.width
+            else:
+                dx0 = ax.viewLim.height
+                dx1 = ax.bbox.height
+            sc = dx1/dx0
+        else:
+            if self._units == 'inches':
+                sc = fig.dpi
+            elif self._units == 'points':
+                sc = fig.dpi / 72.0
+            elif self._units == 'width':
+                sc = ax.bbox.width
+            elif self._units == 'height':
+                sc = ax.bbox.height
+            elif self._units == 'dots':
+                sc = 1.0
+            else:
+                raise ValueError('unrecognized units: %s' % self._units)
+
+        _affine = transforms.Affine2D
+        for x, y, a in zip(self._widths, self._heights, self._angles):
+            trans = _affine().scale(x * sc, y * sc).rotate(a)
+            self._transforms.append(trans)
+
+    def draw(self, renderer):
+        if True: ###not self._transforms:
+            self.set_transforms()
+        return Collection.draw(self, renderer)
+
+    def get_paths(self):
+        return self._paths
+
 class PatchCollection(Collection):
     """
     A generic collection of patches.


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to