Revision: 6401
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6401&view=rev
Author:   efiring
Date:     2008-11-13 08:11:13 +0000 (Thu, 13 Nov 2008)

Log Message:
-----------
Fix autoscaling problems associated with axhline etc.

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

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2008-11-12 20:09:10 UTC (rev 6400)
+++ trunk/matplotlib/CHANGELOG  2008-11-13 08:11:13 UTC (rev 6401)
@@ -1,3 +1,9 @@
+2008-11-12 Add x_isdata and y_isdata attributes to Artist instances,
+           and use them to determine whether either or both
+           coordinates are used when updating dataLim.  This is
+           used to fix autoscaling problems that had been triggered
+           by axhline, axhspan, axvline, axvspan. - EF
+
 2008-11-11 Update the psd(), csd(), cohere(), and specgram() methods
            of Axes and the csd() cohere(), and specgram() functions
            in mlab to be in sync with the changes to psd().

Modified: trunk/matplotlib/lib/matplotlib/artist.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/artist.py   2008-11-12 20:09:10 UTC (rev 
6400)
+++ trunk/matplotlib/lib/matplotlib/artist.py   2008-11-13 08:11:13 UTC (rev 
6401)
@@ -51,6 +51,8 @@
         self.axes = None
         self._remove_method = None
         self._url = None
+        self.x_isdata = True  # False to avoid updating Axes.dataLim with x
+        self.y_isdata = True  #                                      with y
 
     def remove(self):
         """
@@ -319,7 +321,7 @@
         Returns the url
         """
         return self._url
-    
+
     def set_url(self, url):
         """
         Sets the url for the artist

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-11-12 20:09:10 UTC (rev 
6400)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-11-13 08:11:13 UTC (rev 
6401)
@@ -1312,8 +1312,7 @@
         self._set_artist_props(line)
         line.set_clip_path(self.patch)
 
-        if line.get_transform() == self.transData:
-            self._update_line_limits(line)
+        self._update_line_limits(line)
         if not line.get_label():
             line.set_label('_line%d'%len(self.lines))
         self.lines.append(line)
@@ -1322,7 +1321,9 @@
     def _update_line_limits(self, line):
         p = line.get_path()
         if p.vertices.size > 0:
-            self.dataLim.update_from_path(p, self.ignore_existing_data_limits)
+            self.dataLim.update_from_path(p, self.ignore_existing_data_limits,
+                                            updatex=line.x_isdata,
+                                            updatey=line.y_isdata)
             self.ignore_existing_data_limits = False
 
     def add_patch(self, p):
@@ -1356,7 +1357,8 @@
                 transform = (patch.get_data_transform() +
                                     self.transData.inverted())
                 xys = transform.transform(xys)
-            self.update_datalim(xys)
+            self.update_datalim(xys, updatex=patch.x_isdata,
+                                     updatey=patch.y_isdata)
 
 
     def add_table(self, tab):
@@ -1381,7 +1383,7 @@
         for p in self.patches:
             self._update_patch_limits(p)
 
-    def update_datalim(self, xys):
+    def update_datalim(self, xys, updatex=True, updatey=True):
         'Update the data lim bbox with seq of xy tups or equiv. 2-D array'
         # if no data is set currently, the bbox will ignore its
         # limits and set the bound to be the bounds of the xydata.
@@ -1391,7 +1393,8 @@
         if iterable(xys) and not len(xys): return
         if not ma.isMaskedArray(xys):
             xys = np.asarray(xys)
-        self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits)
+        self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits,
+                                           updatex=updatex, updatey=updatey)
         self.ignore_existing_data_limits = False
 
     def update_datalim_numerix(self, x, y):
@@ -2776,11 +2779,9 @@
         trans = mtransforms.blended_transform_factory(
             self.transAxes, self.transData)
         l = mlines.Line2D([xmin,xmax], [y,y], transform=trans, **kwargs)
+        l.x_isdata = False
         self.add_line(l)
-        self.dataLim.y0 = min(self.dataLim.y0, yy)
-        self.dataLim.y1 = max(self.dataLim.y1, yy)
         self.autoscale_view(scalex=False, scaley=scaley)
-
         return l
 
     axhline.__doc__ = cbook.dedent(axhline.__doc__) % martist.kwdocd
@@ -2836,11 +2837,9 @@
         trans = mtransforms.blended_transform_factory(
             self.transData, self.transAxes)
         l = mlines.Line2D([x,x], [ymin,ymax] , transform=trans, **kwargs)
+        l.y_isdata = False
         self.add_line(l)
-        self.dataLim.x0 = min(self.dataLim.x0, xx)
-        self.dataLim.x1 = max(self.dataLim.x1, xx)
         self.autoscale_view(scalex=scalex, scaley=False)
-
         return l
 
     axvline.__doc__ = cbook.dedent(axvline.__doc__) % martist.kwdocd
@@ -2858,7 +2857,7 @@
 
         Draw a horizontal span (rectangle) from *ymin* to *ymax*.
         With the default values of *xmin* = 0 and *xmax* = 1, this
-        always span the xrange, regardless of the xlim settings, even
+        always spans the xrange, regardless of the xlim settings, even
         if you change them, eg. with the :meth:`set_xlim` command.
         That is, the horizontal extent is in axes coords: 0=left,
         0.5=middle, 1.0=right but the *y* location is in data
@@ -2896,6 +2895,7 @@
         verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
         p = mpatches.Polygon(verts, **kwargs)
         p.set_transform(trans)
+        p.x_isdata = False
         self.add_patch(p)
         return p
     axhspan.__doc__ = cbook.dedent(axhspan.__doc__) % martist.kwdocd
@@ -2913,7 +2913,7 @@
 
         Draw a vertical span (rectangle) from *xmin* to *xmax*.  With
         the default values of *ymin* = 0 and *ymax* = 1, this always
-        span the yrange, regardless of the ylim settings, even if you
+        spans the yrange, regardless of the ylim settings, even if you
         change them, eg. with the :meth:`set_ylim` command.  That is,
         the vertical extent is in axes coords: 0=bottom, 0.5=middle,
         1.0=top but the *y* location is in data coordinates.
@@ -2950,6 +2950,7 @@
         verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
         p = mpatches.Polygon(verts, **kwargs)
         p.set_transform(trans)
+        p.y_isdata = False
         self.add_patch(p)
         return p
     axvspan.__doc__ = cbook.dedent(axvspan.__doc__) % martist.kwdocd

Modified: trunk/matplotlib/lib/matplotlib/transforms.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/transforms.py       2008-11-12 20:09:10 UTC 
(rev 6400)
+++ trunk/matplotlib/lib/matplotlib/transforms.py       2008-11-13 08:11:13 UTC 
(rev 6401)
@@ -776,7 +776,8 @@
     def update_from_data(self, x, y, ignore=None):
         """
         Update the bounds of the :class:`Bbox` based on the passed in
-        data.
+        data.  After updating, the bounds will have positive *width*
+        and *height*; *x0* and *y0* will be the minimal values.
 
         *x*: a numpy array of *x*-values
 
@@ -791,10 +792,11 @@
         xy = np.hstack((x.reshape((len(x), 1)), y.reshape((len(y), 1))))
         return self.update_from_data_xy(xy, ignore)
 
-    def update_from_path(self, path, ignore=None):
+    def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
         """
         Update the bounds of the :class:`Bbox` based on the passed in
-        data.
+        data.  After updating, the bounds will have positive *width*
+        and *height*; *x0* and *y0* will be the minimal values.
 
         *path*: a :class:`~matplotlib.path.Path` instance
 
@@ -802,6 +804,10 @@
            - when True, ignore the existing bounds of the :class:`Bbox`.
            - when False, include the existing bounds of the :class:`Bbox`.
            - when None, use the last value passed to :meth:`ignore`.
+
+        *updatex*: when True, update the x values
+
+        *updatey*: when True, update the y values
         """
         if ignore is None:
             ignore = self._ignore
@@ -813,15 +819,20 @@
             path, None, self._points, self._minpos, ignore)
 
         if changed:
-            self._points = points
-            self._minpos = minpos
             self.invalidate()
+            if updatex:
+                self._points[:,0] = points[:,0]
+                self._minpos[0] = minpos[0]
+            if updatey:
+                self._points[:,1] = points[:,1]
+                self._minpos[1] = minpos[1]
 
 
-    def update_from_data_xy(self, xy, ignore=None):
+    def update_from_data_xy(self, xy, ignore=None, updatex=True, updatey=True):
         """
         Update the bounds of the :class:`Bbox` based on the passed in
-        data.
+        data.  After updating, the bounds will have positive *width*
+        and *height*; *x0* and *y0* will be the minimal values.
 
         *xy*: a numpy array of 2D points
 
@@ -829,12 +840,17 @@
            - when True, ignore the existing bounds of the :class:`Bbox`.
            - when False, include the existing bounds of the :class:`Bbox`.
            - when None, use the last value passed to :meth:`ignore`.
+
+        *updatex*: when True, update the x values
+
+        *updatey*: when True, update the y values
         """
         if len(xy) == 0:
             return
 
         path = Path(xy)
-        self.update_from_path(path, ignore=ignore)
+        self.update_from_path(path, ignore=ignore,
+                                    updatex=updatex, updatey=updatey)
 
     def _set_x0(self, val):
         self._points[0, 0] = val


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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to