Revision: 8693
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8693&view=rev
Author:   efiring
Date:     2010-09-09 00:35:12 +0000 (Thu, 09 Sep 2010)

Log Message:
-----------
figure.py: preserve the order in which Axes were added to the figure

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/figure.py

Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py   2010-09-08 15:53:27 UTC (rev 
8692)
+++ trunk/matplotlib/lib/matplotlib/figure.py   2010-09-09 00:35:12 UTC (rev 
8693)
@@ -41,25 +41,35 @@
     """
     Specialization of the Stack to handle all
     tracking of Axes in a Figure.  This requires storing
-    key, axes pairs. The key is based on the args and kwargs
-    used in generating the Axes.
+    key, (ind, axes) pairs. The key is based on the args and kwargs
+    used in generating the Axes. ind is a serial number for tracking
+    the order in which axes were added.
     """
+    def __init__(self):
+        Stack.__init__(self)
+        self._ind = 0
+
     def as_list(self):
         """
         Return a list of the Axes instances that have been added to the figure
         """
-        return [a for k, a in self._elements]
+        ia_list = [a for k, a in self._elements]
+        ia_list.sort()
+        return [a for i, a in ia_list]
 
     def get(self, key):
         """
         Return the Axes instance that was added with *key*.
         If it is not present, return None.
         """
-        return dict(self._elements).get(key)
+        item = dict(self._elements).get(key)
+        if item is None:
+            return None
+        return item[1]
 
     def _entry_from_axes(self, e):
-        k = dict([(a, k) for (k, a) in self._elements])[e]
-        return k, e
+        ind, k = dict([(a, (ind, k)) for (k, (ind, a)) in self._elements])[e]
+        return (k, (ind, e))
 
     def remove(self, a):
         Stack.remove(self, self._entry_from_axes(a))
@@ -92,13 +102,14 @@
 
         if a in self:
             return None
-        return Stack.push(self, (key, a))
+        self._ind += 1
+        return Stack.push(self, (key, (self._ind, a)))
 
     def __call__(self):
         if not len(self._elements):
             return self._default
         else:
-            return self._elements[self._pos][1]
+            return self._elements[self._pos][1][1]
 
     def __contains__(self, a):
         return a in self.as_list()


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

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to