SF.net SVN: matplotlib:[7567] branches/v0_99_maint/lib/matplotlib/lines.py

mdboom@...189... wrote:

Revision: 7567
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7567&view=rev
Author: mdboom
Date: 2009-08-25 15:31:10 +0000 (Tue, 25 Aug 2009)

Log Message:
-----------
Support Line2D objects without associated Axes objects.

Modified Paths:
--------------
    branches/v0_99_maint/lib/matplotlib/lines.py

Modified: branches/v0_99_maint/lib/matplotlib/lines.py

--- branches/v0_99_maint/lib/matplotlib/lines.py 2009-08-25 11:54:24 UTC (rev 7566)
+++ branches/v0_99_maint/lib/matplotlib/lines.py 2009-08-25 15:31:10 UTC (rev 7567)
@@ -459,7 +459,7 @@
         self._y = self._xy[:, 1] # just a view
          self._subslice = False
- if len(x) > 100 and self._is_sorted(x):
+ if self.axes and len(x) > 100 and self._is_sorted(x):
             self._subslice = True
         if hasattr(self, '_path'):
             interpolation_steps = self._path._interpolation_steps
@@ -496,7 +496,7 @@
     def draw(self, renderer):
         if self._invalid:
             self.recache()
- if self._subslice:
+ if self._subslice and self.axes:
             # Need to handle monotonically decreasing case also...
             x0, x1 = self.axes.get_xbound()
             i0, = self._x.searchsorted([x0], 'left')

Mike,

I'm curious--why are both changes needed? Shouldn't the setting of self._subslice in the first chunk be enough? If not, it suggests that there are more general design problems here. Can a line object have an associated axes when it is created (or when data are fed to it) and then lose that axes attribute by the time draw() is called? If so, then it seems like the second chunk is the right one to keep, and the first one is useless.

Eric