Revision: 8988
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8988&view=rev
Author:   weathergod
Date:     2011-02-18 19:28:29 +0000 (Fri, 18 Feb 2011)

Log Message:
-----------
scatter() now supports empty arrays as input (i.e., scatter([], []) is now 
valid).
Enabling this required fixes in both scatter() and in collections.py.
Collections now support empty versions of themselves more correctly due to 
these fixes.

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

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2011-02-17 16:44:28 UTC (rev 8987)
+++ trunk/matplotlib/CHANGELOG  2011-02-18 19:28:29 UTC (rev 8988)
@@ -1,3 +1,6 @@
+2011-02-18 scatter([], []) is now valid.  Also fixed issues
+           with empty collections - BVR
+
 2011-02-07 Quick workaround for dviread bug #3175113 - JKS
 
 2011-02-05 Add cbook memory monitoring for Windows, using

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2011-02-17 16:44:28 UTC (rev 
8987)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2011-02-18 19:28:29 UTC (rev 
8988)
@@ -5832,24 +5832,17 @@
             else:
                 collection.autoscale_None()
 
-        temp_x = x
-        temp_y = y
-
-        minx = np.amin(temp_x)
-        maxx = np.amax(temp_x)
-        miny = np.amin(temp_y)
-        maxy = np.amax(temp_y)
-
-        w = maxx-minx
-        h = maxy-miny
-
         # the pad is a little hack to deal with the fact that we don't
         # want to transform all the symbols whose scales are in points
         # to data coords to get the exact bounding box for efficiency
         # reasons.  It can be done right if this is deemed important
-        padx, pady = 0.05*w, 0.05*h
-        corners = (minx-padx, miny-pady), (maxx+padx, maxy+pady)
-        self.update_datalim( corners)
+        # Also, only bother with this padding if there is anything to draw.
+        if self._xmargin < 0.05 and x.size > 0 :
+            self.set_xmargin(0.05)
+
+        if self._ymargin < 0.05 and x.size > 0 :
+            self.set_ymargin(0.05)
+
         self.autoscale_view()
 
         # add the collection last

Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py      2011-02-17 16:44:28 UTC 
(rev 8987)
+++ trunk/matplotlib/lib/matplotlib/collections.py      2011-02-18 19:28:29 UTC 
(rev 8988)
@@ -59,6 +59,8 @@
     scalar mappable will be made to set the face colors.
     """
     _offsets = np.array([], np.float_)
+    # _offsets must be a Nx2 array!
+    _offsets.shape = (0, 2)
     _transOffset = transforms.IdentityTransform()
     _transforms = []
 
@@ -95,10 +97,11 @@
 
         self._uniform_offsets = None
         self._offsets = np.array([], np.float_)
+        # Force _offsets to be Nx2
+        self._offsets.shape = (0, 2)
         if offsets is not None:
             offsets = np.asarray(offsets)
-            if len(offsets.shape) == 1:
-                offsets = offsets[np.newaxis,:]  # Make it Nx2.
+            offsets.shape = (-1, 2)             # Make it Nx2
             if transOffset is not None:
                 self._offsets = offsets
                 self._transOffset = transOffset
@@ -148,13 +151,17 @@
         transOffset = self._transOffset
         offsets = self._offsets
         paths = self.get_paths()
+
+
         if not transform.is_affine:
             paths = [transform.transform_path_non_affine(p) for p in paths]
             transform = transform.get_affine()
         if not transOffset.is_affine:
             offsets = transOffset.transform_non_affine(offsets)
             transOffset = transOffset.get_affine()
+
         offsets = np.asarray(offsets, np.float_)
+        offsets.shape = (-1, 2)                     # Make it Nx2
 
         result = mpath.get_path_collection_extents(
             transform.frozen(), paths, self.get_transforms(),
@@ -176,6 +183,7 @@
         offsets = self._offsets
         paths = self.get_paths()
 
+
         if self.have_units():
             paths = []
             for path in self.get_paths():
@@ -184,17 +192,19 @@
                 xs = self.convert_xunits(xs)
                 ys = self.convert_yunits(ys)
                 paths.append(mpath.Path(zip(xs, ys), path.codes))
-            if len(self._offsets):
-                xs = self.convert_xunits(self._offsets[:,0])
-                ys = self.convert_yunits(self._offsets[:,1])
+
+            if offsets.size > 0:
+                xs = self.convert_xunits(offsets[:,0])
+                ys = self.convert_yunits(offsets[:,1])
                 offsets = zip(xs, ys)
 
         offsets = np.asarray(offsets, np.float_)
+        offsets.shape = (-1, 2)             # Make it Nx2
 
         if not transform.is_affine:
             paths = [transform.transform_path_non_affine(path) for path in 
paths]
             transform = transform.get_affine()
-        if not transOffset.is_affine:
+        if not transOffset.is_affine :
             offsets = transOffset.transform_non_affine(offsets)
             transOffset = transOffset.get_affine()
 
@@ -258,8 +268,7 @@
         ACCEPTS: float or sequence of floats
         """
         offsets = np.asarray(offsets, np.float_)
-        if len(offsets.shape) == 1:
-            offsets = offsets[np.newaxis,:]  # Make it Nx2.
+        offsets.shape = (-1, 2)             # Make it Nx2
         #This decision is based on how they are initialized above
         if self._uniform_offsets is None:
             self._offsets = offsets
@@ -1221,6 +1230,7 @@
                 offsets = zip(xs, ys)
 
         offsets = np.asarray(offsets, np.float_)
+        offsets.shape = (-1, 2)                 # Make it Nx2
 
         self.update_scalarmappable()
 


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

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to