Revision: 5403
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5403&view=rev
Author:   mdboom
Date:     2008-06-05 10:09:04 -0700 (Thu, 05 Jun 2008)

Log Message:
-----------
Fix dpi-changing-related bugs in Axes.scatter()

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

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2008-06-05 17:06:16 UTC (rev 5402)
+++ trunk/matplotlib/CHANGELOG  2008-06-05 17:09:04 UTC (rev 5403)
@@ -1,3 +1,6 @@
+2008-06-05 Fix some dpi-changing-related problems with PolyCollection,
+           as called by Axes.scatter() - MGD
+
 2008-06-05 Fix image drawing so there is no extra space to the right
            or bottom - MGD
 

Modified: trunk/matplotlib/examples/api/collections_demo.py
===================================================================
--- trunk/matplotlib/examples/api/collections_demo.py   2008-06-05 17:06:16 UTC 
(rev 5402)
+++ trunk/matplotlib/examples/api/collections_demo.py   2008-06-05 17:09:04 UTC 
(rev 5403)
@@ -33,8 +33,9 @@
 spiral = zip(xx,yy)
 
 # Make some offsets
-xo = N.random.randn(npts)
-yo = N.random.randn(npts)
+rs = N.random.RandomState([12345678])
+xo = rs.randn(npts)
+yo = rs.randn(npts)
 xyo = zip(xo, yo)
 
 # Make a list of colors cycling through the rgbcmyk series.
@@ -45,7 +46,7 @@
 a = fig.add_subplot(2,2,1)
 col = collections.LineCollection([spiral], offsets=xyo,
                                 transOffset=a.transData)
-trans = transforms.Affine2D().scale(fig.dpi/72.0)
+trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
 col.set_transform(trans)  # the points to pixels transform
     # Note: the first argument to the collection initializer
     # must be a list of sequences of x,y tuples; we have only
@@ -112,7 +113,7 @@
 xx = (0.2 + (ym-yy)/ym)**2 * N.cos(yy-0.4) * 0.5
 segs = []
 for i in range(ncurves):
-    xxx = xx + 0.02*N.random.randn(nverts)
+    xxx = xx + 0.02*rs.randn(nverts)
     curve = zip(xxx, yy*100)
     segs.append(curve)
 

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-06-05 17:06:16 UTC (rev 
5402)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-06-05 17:09:04 UTC (rev 
5403)
@@ -4603,15 +4603,8 @@
             rescale = np.sqrt(max(verts[:,0]**2+verts[:,1]**2))
             verts /= rescale
 
-            scales = np.asarray(scales)
-            scales = np.sqrt(scales * self.figure.dpi / 72.)
-            if len(scales)==1:
-                verts = [scales[0]*verts]
-            else:
-                # todo -- make this nx friendly
-                verts = [verts*s for s in scales]
             collection = mcoll.PolyCollection(
-                verts,
+                verts, scales,
                 facecolors = colors,
                 edgecolors = edgecolors,
                 linewidths = linewidths,

Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py      2008-06-05 17:06:16 UTC 
(rev 5402)
+++ trunk/matplotlib/lib/matplotlib/collections.py      2008-06-05 17:09:04 UTC 
(rev 5403)
@@ -492,15 +492,19 @@
         renderer.close_group(self.__class__.__name__)
 
 class PolyCollection(Collection):
-    def __init__(self, verts, **kwargs):
+    def __init__(self, verts, sizes = (1, ), **kwargs):
         """
         verts is a sequence of ( verts0, verts1, ...) where verts_i is
         a sequence of xy tuples of vertices, or an equivalent
         numpy array of shape (nv,2).
 
+        sizes gives the area of the circle circumscribing the
+        polygon in points^2
+
         %(Collection)s
         """
         Collection.__init__(self,**kwargs)
+        self._sizes = sizes
         self.set_verts(verts)
     __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
 
@@ -511,6 +515,15 @@
     def get_paths(self):
         return self._paths
 
+    def draw(self, renderer):
+        # sizes is the area of the circle circumscribing the polygon
+        # in points^2
+        self._transforms = [
+            transforms.Affine2D().scale(
+                (np.sqrt(x) * renderer.dpi / 72.0))
+            for x in self._sizes]
+        return Collection.draw(self, renderer)
+
 class BrokenBarHCollection(PolyCollection):
     """
     A colleciton of horizontal bars spanning yrange with a sequence of


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

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to