Revision: 4577
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4577&view=rev
Author:   mdboom
Date:     2007-12-04 08:01:06 -0800 (Tue, 04 Dec 2007)

Log Message:
-----------
Fix bug when collection is empty.

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/axes.py

Modified: branches/transforms/lib/matplotlib/axes.py
===================================================================
--- branches/transforms/lib/matplotlib/axes.py  2007-12-04 14:38:48 UTC (rev 
4576)
+++ branches/transforms/lib/matplotlib/axes.py  2007-12-04 16:01:06 UTC (rev 
4577)
@@ -21,6 +21,7 @@
 from matplotlib import lines as mlines
 from matplotlib import mlab
 from matplotlib import patches as mpatches
+from matplotlib import path as mpath
 from matplotlib import quiver as mquiver
 from matplotlib import scale as mscale
 from matplotlib import table as mtable
@@ -770,13 +771,14 @@
 
         self.grid(self._gridOn)
         props = font_manager.FontProperties(size=rcParams['axes.titlesize'])
-        self.title =  mtext.Text(
-            x=0.5, y=1.02, text='',
+        self.titleOffsetTrans = mtransforms.Affine2D()
+        self.title = mtext.Text(
+            x=0.5, y=1.00, text='',
             fontproperties=props,
             verticalalignment='bottom',
             horizontalalignment='center',
             )
-        self.title.set_transform(self.transAxes)
+        self.title.set_transform(self.transAxes + self.titleOffsetTrans)
         self.title.set_clip_box(None)
 
         self._set_artist_props(self.title)
@@ -800,6 +802,8 @@
         self.xaxis.set_clip_path(self.axesPatch)
         self.yaxis.set_clip_path(self.axesPatch)
 
+        self.titleOffsetTrans.clear()
+
     def clear(self):
         'clear the axes'
         self.cla()
@@ -905,14 +909,14 @@
         ysize = max(math.fabs(ymax-ymin), 1e-30)
         return ysize/xsize
 
-    def apply_aspect(self):
+    def apply_aspect(self, currentPosition):
         '''
         Use self._aspect and self._adjustable to modify the
         axes box or the view limits.
         '''
         aspect = self.get_aspect()
         if aspect == 'auto':
-            self.set_position( self._originalPosition , 'active')
+            self.set_position(currentPosition, 'active')
             return
 
         if aspect == 'equal':
@@ -929,7 +933,7 @@
         fig_aspect = figH/figW
         if self._adjustable == 'box':
             box_aspect = A * self.get_data_ratio()
-            pb = self._originalPosition.frozen()
+            pb = currentPosition.frozen()
             pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
             self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
             return
@@ -1289,25 +1293,48 @@
             YL = ylocator.autoscale()
             self.set_ybound(YL)
 
+    def adjust_for_axis_text(self, renderer):
+        pad_pixels = rcParams['xtick.major.pad'] * self.figure.dpi / 72.0
+        inverse_transFigure = self.figure.transFigure.inverted()
+        t_text, b_text = self.xaxis.get_text_heights(renderer)
+        l_text, r_text = self.yaxis.get_text_widths(renderer)
+        title_height = self.title.get_window_extent(renderer).height
+        title_height += pad_pixels * 2.0
+        original_t_text = t_text
+
+        ((l_text, t_text),
+         (r_text, b_text),
+         (dummy, title_height)) = inverse_transFigure.transform(
+            ((l_text, t_text),
+             (r_text, b_text),
+             (0.0, title_height)))
+        x0, y0, x1, y1 = self.get_position(True).extents
+        # Adjust the title
+        self.titleOffsetTrans.clear().translate(
+            0, original_t_text + pad_pixels * 2.0)
+        return mtransforms.Bbox.from_extents(
+            x0 + l_text, y0 + b_text, x1 - r_text,
+            y1 - t_text - title_height)
+
     #### Drawing
     def draw(self, renderer=None, inframe=False):
         "Draw everything (plot lines, axes, labels)"
-       if renderer is None:
+        if renderer is None:
             renderer = self._cachedRenderer
 
         if renderer is None:
             raise RuntimeError('No renderer defined')
         if not self.get_visible(): return
         renderer.open_group('axes')
-        self.apply_aspect()
 
+        currentPosition = self.adjust_for_axis_text(renderer)
+        self.apply_aspect(currentPosition)
+
         if self.axison and self._frameon:
             self.axesPatch.draw(renderer)
 
         artists = []
 
-
-
         if len(self.images)<=1 or renderer.option_image_nocomposite():
             for im in self.images:
                 im.draw(renderer)
@@ -1319,7 +1346,6 @@
             ims = [(im.make_image(mag),0,0)
                    for im in self.images if im.get_visible()]
 
-
             im = mimage.from_images(self.bbox.height*mag,
                                     self.bbox.width*mag,
                                     ims)
@@ -1360,6 +1386,14 @@
             a.draw(renderer)
 
         renderer.close_group('axes')
+
+#         ### DEBUGGING
+#         gc = renderer.new_gc()
+#         gc.set_linewidth(2.0)
+#         x0, y0, x1, y1 = self.get_position(True).extents
+#         renderer.draw_path(gc, mpath.Path(
+#                            [[x0, y0], [x0, y1], [x1, y1], [x1, y0], [x0, 
y0]]),
+#                            self.figure.transFigure)
         self._cachedRenderer = renderer
 
     def draw_artist(self, a):


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

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to