Revision: 4909
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4909&view=rev
Author:   mdboom
Date:     2008-01-31 06:21:49 -0800 (Thu, 31 Jan 2008)

Log Message:
-----------
Fig dpi-changing-related bug where tick label padding was not updating
(Thanks Eric Firing for finding this).

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/axes.py
    trunk/matplotlib/lib/matplotlib/axis.py
    trunk/matplotlib/lib/matplotlib/collections.py
    trunk/matplotlib/lib/matplotlib/figure.py
    trunk/matplotlib/lib/matplotlib/patches.py
    trunk/matplotlib/lib/matplotlib/projections/geo.py
    trunk/matplotlib/lib/matplotlib/projections/polar.py
    trunk/matplotlib/lib/matplotlib/text.py
    trunk/matplotlib/lib/matplotlib/transforms.py

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-01-29 20:50:53 UTC (rev 
4908)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-01-31 14:21:49 UTC (rev 
4909)
@@ -595,13 +595,13 @@
         """
         return self._xaxis_transform
 
-    def get_xaxis_text1_transform(self, pad_pixels):
+    def get_xaxis_text1_transform(self, pad_points):
         """
         Get the transformation used for drawing x-axis labels, which
-        will add the given number of pad_pixels between the axes and
-        the label.  The x-direction is in data coordinates and the
-        y-direction is in axis coordinates.  Returns a 3-tuple of the
-        form:
+        will add the given amount of padding (in points) between the
+        axes and the label.  The x-direction is in data coordinates
+        and the y-direction is in axis coordinates.  Returns a 3-tuple
+        of the form:
 
           (transform, valign, halign)
 
@@ -612,14 +612,15 @@
         need to place axis elements in different locations.
         """
         return (self._xaxis_transform +
-                mtransforms.Affine2D().translate(0, -1 * pad_pixels),
+                mtransforms.ScaledTranslation(0, -1 * pad_points / 72.0,
+                                              self.figure.dpi_scale_trans),
                 "top", "center")
 
-    def get_xaxis_text2_transform(self, pad_pixels):
+    def get_xaxis_text2_transform(self, pad_points):
         """
         Get the transformation used for drawing the secondary x-axis
-        labels, which will add the given number of pad_pixels between
-        the axes and the label.  The x-direction is in data
+        labels, which will add the given amount of padding (in points)
+        between the axes and the label.  The x-direction is in data
         coordinates and the y-direction is in axis coordinates.
         Returns a 3-tuple of the form:
 
@@ -632,7 +633,8 @@
         need to place axis elements in different locations.
         """
         return (self._xaxis_transform +
-                mtransforms.Affine2D().translate(0, pad_pixels),
+                mtransforms.ScaledTranslation(0, pad_points / 72.0,
+                                              self.figure.dpi_scale_trans),
                 "bottom", "center")
 
     def get_yaxis_transform(self):
@@ -647,13 +649,13 @@
         """
         return self._yaxis_transform
 
-    def get_yaxis_text1_transform(self, pad_pixels):
+    def get_yaxis_text1_transform(self, pad_points):
         """
         Get the transformation used for drawing y-axis labels, which
-        will add the given number of pad_pixels between the axes and
-        the label.  The x-direction is in axis coordinates and the
-        y-direction is in data coordinates.  Returns a 3-tuple of the
-        form:
+        will add the given amount of padding (in points) between the
+        axes and the label.  The x-direction is in axis coordinates
+        and the y-direction is in data coordinates.  Returns a 3-tuple
+        of the form:
 
           (transform, valign, halign)
 
@@ -664,14 +666,15 @@
         need to place axis elements in different locations.
         """
         return (self._yaxis_transform +
-                mtransforms.Affine2D().translate(-1 * pad_pixels, 0),
+                mtransforms.ScaledTranslation(-1 * pad_points / 72.0, 0,
+                                               self.figure.dpi_scale_trans),
                 "center", "right")
 
-    def get_yaxis_text2_transform(self, pad_pixels):
+    def get_yaxis_text2_transform(self, pad_points):
         """
         Get the transformation used for drawing the secondary y-axis
-        labels, which will add the given number of pad_pixels between
-        the axes and the label.  The x-direction is in axis
+        labels, which will add the given amount of padding (in points)
+        between the axes and the label.  The x-direction is in axis
         coordinates and the y-direction is in data coordinates.
         Returns a 3-tuple of the form:
 
@@ -684,7 +687,8 @@
         need to place axis elements in different locations.
         """
         return (self._yaxis_transform +
-                mtransforms.Affine2D().translate(pad_pixels, 0),
+                mtransforms.ScaledTranslation(-1 * pad_points / 72.0, 0,
+                                               self.figure.dpi_scale_trans),
                 "center", "left")
 
     def _update_transScale(self):
@@ -4287,7 +4291,6 @@
         if sym is not None:
             if symstyle==0:
                 collection = mcoll.RegularPolyCollection(
-                    self.figure.dpi,
                     numsides, rotation, scales,
                     facecolors = colors,
                     edgecolors = edgecolors,
@@ -4297,7 +4300,6 @@
                     )
             elif symstyle==1:
                 collection = mcoll.StarPolygonCollection(
-                    self.figure.dpi,
                     numsides, rotation, scales,
                     facecolors = colors,
                     edgecolors = edgecolors,
@@ -4307,7 +4309,6 @@
                     )
             elif symstyle==2:
                 collection = mcoll.AsteriskPolygonCollection(
-                    self.figure.dpi,
                     numsides, rotation, scales,
                     facecolors = colors,
                     edgecolors = edgecolors,
@@ -4316,6 +4317,7 @@
                     transOffset = self.transData,
                     )
         else:
+            # MGDTODO: This has dpi problems
             # rescale verts
             rescale = npy.sqrt(max(verts[:,0]**2+verts[:,1]**2))
             verts /= rescale

Modified: trunk/matplotlib/lib/matplotlib/axis.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axis.py     2008-01-29 20:50:53 UTC (rev 
4908)
+++ trunk/matplotlib/lib/matplotlib/axis.py     2008-01-31 14:21:49 UTC (rev 
4909)
@@ -223,9 +223,9 @@
         # get the affine as an a,b,c,d,tx,ty list
         # x in data coords, y in axes coords
         #t =  Text(
-        trans, vert, horiz = 
self.axes.get_xaxis_text1_transform(self.get_pad_pixels())
+        trans, vert, horiz = self.axes.get_xaxis_text1_transform(self._pad)
 
-        t =  TextWithDash(
+        t = TextWithDash(
             x=0, y=0,
             fontproperties=FontProperties(size=rcParams['xtick.labelsize']),
             color=rcParams['xtick.color'],
@@ -245,7 +245,7 @@
         'Get the default Text 2 instance'
         # x in data coords, y in axes coords
         #t =  Text(
-        trans, vert, horiz = 
self.axes.get_xaxis_text2_transform(self.get_pad_pixels())
+        trans, vert, horiz = self.axes.get_xaxis_text2_transform(self._pad)
 
         t = TextWithDash(
             x=0, y=1,
@@ -358,7 +358,7 @@
         'Get the default Text instance'
         # x in axes coords, y in data coords
         #t =  Text(
-        trans, vert, horiz = 
self.axes.get_yaxis_text1_transform(self.get_pad_pixels())
+        trans, vert, horiz = self.axes.get_yaxis_text1_transform(self._pad)
 
         t = TextWithDash(
             x=0, y=0,
@@ -378,7 +378,7 @@
         'Get the default Text instance'
         # x in axes coords, y in data coords
         #t =  Text(
-        trans, vert, horiz = 
self.axes.get_yaxis_text2_transform(self.get_pad_pixels())
+        trans, vert, horiz = self.axes.get_yaxis_text2_transform(self._pad)
 
         t = TextWithDash(
             x=1, y=0,

Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py      2008-01-29 20:50:53 UTC 
(rev 4908)
+++ trunk/matplotlib/lib/matplotlib/collections.py      2008-01-31 14:21:49 UTC 
(rev 4909)
@@ -505,7 +505,6 @@
     _path_generator = mpath.Path.unit_regular_polygon
 
     def __init__(self,
-                 dpi,
                  numsides,
                  rotation = 0 ,
                  sizes = (1,),
@@ -532,7 +531,6 @@
         black = (0,0,0,1)
 
         collection = RegularPolyCollection(
-            fig.dpi,
             numsides=5, # a pentagon
             rotation=0,
             sizes=(50,),
@@ -545,18 +543,21 @@
         """
         Collection.__init__(self,**kwargs)
         self._sizes = sizes
-        self._dpi = dpi
         self._paths = [self._path_generator(numsides)]
+        self._rotation = rotation
+        self.set_transform(transforms.IdentityTransform())
+
+    __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
+
+    def draw(self, renderer):
         # sizes is the area of the circle circumscribing the polygon
         # in points^2
         self._transforms = [
-            transforms.Affine2D().rotate(-rotation).scale(
-                (math.sqrt(x) * self._dpi / 72.0) / math.sqrt(math.pi))
-            for x in sizes]
-        self.set_transform(transforms.IdentityTransform())
+            transforms.Affine2D().rotate(-self._rotation).scale(
+                (npy.sqrt(x) * renderer.dpi / 72.0) / npy.sqrt(npy.pi))
+            for x in self._sizes]
+        return Collection.draw(self, renderer)
 
-    __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
-
     def get_paths(self):
         return self._paths
 

Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py   2008-01-29 20:50:53 UTC (rev 
4908)
+++ trunk/matplotlib/lib/matplotlib/figure.py   2008-01-31 14:21:49 UTC (rev 
4909)
@@ -122,10 +122,10 @@
         if facecolor is None: facecolor = rcParams['figure.facecolor']
         if edgecolor is None: edgecolor = rcParams['figure.edgecolor']
 
-        self._dpi_scale_trans = Affine2D()
+        self.dpi_scale_trans = Affine2D()
         self.dpi = dpi
         self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
-        self.bbox = TransformedBbox(self.bbox_inches, self._dpi_scale_trans)
+        self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)
 
         self.frameon = frameon
 
@@ -157,7 +157,7 @@
         return self._dpi
     def _set_dpi(self, dpi):
         self._dpi = dpi
-        self._dpi_scale_trans.clear().scale(dpi, dpi)
+        self.dpi_scale_trans.clear().scale(dpi, dpi)
     dpi = property(_get_dpi, _set_dpi)
 
     def enable_auto_layout(self, setting=True):

Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py  2008-01-29 20:50:53 UTC (rev 
4908)
+++ trunk/matplotlib/lib/matplotlib/patches.py  2008-01-31 14:21:49 UTC (rev 
4909)
@@ -727,11 +727,11 @@
     def __str__(self):
         return "YAArrow()"
 
-    def __init__(self, dpi, xytip, xybase, width=4, frac=0.1, headwidth=12, 
**kwargs):
+    def __init__(self, figure, xytip, xybase, width=4, frac=0.1, headwidth=12, 
**kwargs):
         """
         xytip : (x,y) location of arrow tip
         xybase : (x,y) location the arrow base mid point
-        dpi : the figure dpi instance (fig.dpi)
+        figure : the figure instance (fig.dpi)
         width : the width of the arrow in points
         frac  : the fraction of the arrow length occupied by the head
         headwidth : the width of the base of the arrow head in points
@@ -740,7 +740,7 @@
         %(Patch)s
 
         """
-        self.dpi = dpi
+        self.figure = figure
         self.xytip = xytip
         self.xybase = xybase
         self.width = width
@@ -756,8 +756,8 @@
         # the base vertices
         x1, y1 = self.xytip
         x2, y2 = self.xybase
-        k1 = self.width*self.dpi/72./2.
-        k2 = self.headwidth*self.dpi/72./2.
+        k1 = self.width*self.figure.dpi/72./2.
+        k2 = self.headwidth*self.figure.dpi/72./2.
         xb1, yb1, xb2, yb2 = self.getpoints(x1, y1, x2, y2, k1)
 
         # a point on the segment 20% of the distance from the tip to the base

Modified: trunk/matplotlib/lib/matplotlib/projections/geo.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/projections/geo.py  2008-01-29 20:50:53 UTC 
(rev 4908)
+++ trunk/matplotlib/lib/matplotlib/projections/geo.py  2008-01-31 14:21:49 UTC 
(rev 4909)
@@ -120,19 +120,19 @@
     def get_xaxis_transform(self):
         return self._xaxis_transform
 
-    def get_xaxis_text1_transform(self, pixelPad):
+    def get_xaxis_text1_transform(self, pad):
         return self._xaxis_text1_transform, 'bottom', 'center'
 
-    def get_xaxis_text2_transform(self, pixelPad):
+    def get_xaxis_text2_transform(self, pad):
         return self._xaxis_text2_transform, 'top', 'center'
 
     def get_yaxis_transform(self):
         return self._yaxis_transform
 
-    def get_yaxis_text1_transform(self, pixelPad):
+    def get_yaxis_text1_transform(self, pad):
         return self._yaxis_text1_transform, 'center', 'right'
 
-    def get_yaxis_text2_transform(self, pixelPad):
+    def get_yaxis_text2_transform(self, pad):
         return self._yaxis_text2_transform, 'center', 'left'
 
     def get_axes_patch(self):

Modified: trunk/matplotlib/lib/matplotlib/projections/polar.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/projections/polar.py        2008-01-29 
20:50:53 UTC (rev 4908)
+++ trunk/matplotlib/lib/matplotlib/projections/polar.py        2008-01-31 
14:21:49 UTC (rev 4909)
@@ -252,19 +252,19 @@
     def get_xaxis_transform(self):
         return self._xaxis_transform
 
-    def get_xaxis_text1_transform(self, pixelPad):
+    def get_xaxis_text1_transform(self, pad):
         return self._xaxis_text1_transform, 'center', 'center'
 
-    def get_xaxis_text2_transform(self, pixelPad):
+    def get_xaxis_text2_transform(self, pad):
         return self._xaxis_text2_transform, 'center', 'center'
 
     def get_yaxis_transform(self):
         return self._yaxis_transform
 
-    def get_yaxis_text1_transform(self, pixelPad):
+    def get_yaxis_text1_transform(self, pad):
         return self._yaxis_text1_transform, 'center', 'center'
 
-    def get_yaxis_text2_transform(self, pixelPad):
+    def get_yaxis_text2_transform(self, pad):
         return self._yaxis_text2_transform, 'center', 'center'
 
     def get_axes_patch(self):

Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py     2008-01-29 20:50:53 UTC (rev 
4908)
+++ trunk/matplotlib/lib/matplotlib/text.py     2008-01-31 14:21:49 UTC (rev 
4909)
@@ -1195,7 +1195,7 @@
             dx = shrink*r*math.cos(theta)
             dy = shrink*r*math.sin(theta)
 
-            self.arrow = YAArrow(self.figure.dpi, (x0+dx,y0+dy), (x-dx, y-dy),
+            self.arrow = YAArrow(self.figure, (x0+dx,y0+dy), (x-dx, y-dy),
                             width=width, headwidth=headwidth, frac=frac,
                             **d)
             self.arrow.set_clip_box(self.get_clip_box())

Modified: trunk/matplotlib/lib/matplotlib/transforms.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/transforms.py       2008-01-29 20:50:53 UTC 
(rev 4908)
+++ trunk/matplotlib/lib/matplotlib/transforms.py       2008-01-31 14:21:49 UTC 
(rev 4909)
@@ -1898,6 +1898,32 @@
     get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
 
 
+class ScaledTranslation(Affine2DBase):
+    def __init__(self, xt, yt, scale_trans):
+        Affine2DBase.__init__(self)
+        self._t = (xt, yt)
+        self._scale_trans = scale_trans
+        self.set_children(scale_trans)
+        self._mtx = None
+        self._inverted = None
+
+    def __repr__(self):
+        return "ScaledTranslation(%s)" % (self._t)
+    __str__ = __repr__
+
+    def get_matrix(self):
+        if self._invalid:
+            xt, yt = self._scale_trans.transform_point(self._t)
+            self._mtx = npy.array([[1.0, 0.0, xt],
+                                   [0.0, 1.0, yt],
+                                   [0.0, 0.0, 1.0]],
+                                  npy.float_)
+            self._invalid = 0
+            self._inverted = None
+        return self._mtx
+    get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
+
+
 class TransformedPath(TransformNode):
     """
     A TransformedPath caches a non-affine transformed copy of the


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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to