Revision: 6829
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6829&view=rev
Author:   leejjoon
Date:     2009-01-26 16:39:14 +0000 (Mon, 26 Jan 2009)

Log Message:
-----------
Improved tight bbox option of the savefig

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

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-01-26 14:40:09 UTC (rev 6828)
+++ trunk/matplotlib/CHANGELOG  2009-01-26 16:39:14 UTC (rev 6829)
@@ -1,3 +1,5 @@
+2009-01-26 Improved tight bbox option of the savefig. - JJL
+
 2009-01-26 Make curves and NaNs play nice together - MGD
 
 2009-01-21 Changed the defaults of acorr and xcorr to use

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2009-01-26 14:40:09 UTC (rev 
6828)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2009-01-26 16:39:14 UTC (rev 
6829)
@@ -7377,6 +7377,40 @@
                                                  integer=True))
         return im
 
+
+    def get_tightbbox(self, renderer):
+        """
+        return the tight bounding box of the axes.
+        The dimension of the Bbox in canvas coordinate.
+        """
+        
+        artists = []
+        bb = []
+
+        artists.append(self)
+
+        if self.title.get_visible():
+            artists.append(self.title)
+
+        if self.xaxis.get_visible():
+            artists.append(self.xaxis.label)
+            bbx1, bbx2 = self.xaxis.get_ticklabel_extents(renderer)
+            bb.extend([bbx1, bbx2])
+        if self.yaxis.get_visible():
+            artists.append(self.yaxis.label)
+            bby1, bby2 = self.yaxis.get_ticklabel_extents(renderer)
+            bb.extend([bby1, bby2])
+
+
+        bb.extend([c.get_window_extent(renderer) for c in artists])
+
+        _bbox = mtransforms.Bbox.union([b for b in bb if b.width!=0 or 
b.height!=0])
+
+        return _bbox
+
+
+
+
 class SubplotBase:
     """
     Base class for subplots, which are :class:`Axes` instances with
@@ -7514,6 +7548,8 @@
         for label in self.get_yticklabels():
             label.set_visible(firstcol)
 
+
+
 _subplot_classes = {}
 def subplot_class_factory(axes_class=None):
     # This makes a new class that inherits from SubclassBase and the

Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backend_bases.py    2009-01-26 14:40:09 UTC 
(rev 6828)
+++ trunk/matplotlib/lib/matplotlib/backend_bases.py    2009-01-26 16:39:14 UTC 
(rev 6829)
@@ -1479,7 +1479,25 @@
         origBboxInches = fig.bbox_inches
         _boxout = fig.transFigure._boxout
 
+        asp_list = []
+        locator_list = []
+        for ax in fig.axes:
+            pos = ax.get_position(original=False).frozen()
+            locator_list.append(ax.get_axes_locator())
+            asp_list.append(ax.get_aspect())
+
+            def _l(a, r, pos=pos): return pos
+            ax.set_axes_locator(_l)
+            ax.set_aspect("auto")
+
+
+
         def restore_bbox():
+
+            for ax, asp, loc in zip(fig.axes, asp_list, locator_list):
+                ax.set_aspect(asp)
+                ax.set_axes_locator(loc)
+
             fig.bbox = origBbox
             fig.bbox_inches = origBboxInches
             fig.transFigure._boxout = _boxout

Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py   2009-01-26 14:40:09 UTC (rev 
6828)
+++ trunk/matplotlib/lib/matplotlib/figure.py   2009-01-26 16:39:14 UTC (rev 
6829)
@@ -1111,23 +1111,11 @@
         ticklabels. Needs improvement.
         """
 
-        artists = []
         bb = []
         for ax in self.axes:
+            if ax.get_visible():
+                bb.append(ax.get_tightbbox(renderer))
 
-            artists.append(ax.xaxis.label)
-            artists.append(ax.yaxis.label)
-            artists.append(ax.title)
-            artists.append(ax)
-
-            bbx1, bbx2 = ax.xaxis.get_ticklabel_extents(renderer)
-            bby1, bby2 = ax.yaxis.get_ticklabel_extents(renderer)
-            bb.extend([bbx1, bbx2, bby1, bby2])
-
-
-        bb.extend([c.get_window_extent(renderer) for c in artists \
-                   if c.get_visible()])
-
         _bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])
 
         bbox_inches = TransformedBbox(_bbox,


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:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to