Revision: 8682
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8682&view=rev
Author:   efiring
Date:     2010-09-06 01:51:58 +0000 (Mon, 06 Sep 2010)

Log Message:
-----------
figure.py, axes tracking: ensure a unique key is provided.

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

Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py   2010-09-05 19:33:42 UTC (rev 
8681)
+++ trunk/matplotlib/lib/matplotlib/figure.py   2010-09-06 01:51:58 UTC (rev 
8682)
@@ -82,6 +82,14 @@
             hash(key)
         except TypeError:
             raise ValueError("first argument, %s, is not a valid key" % key)
+
+        a_existing = self.get(key)
+        if a_existing is not None:
+            Stack.remove(self, (key, a_existing))
+            warnings.Warn(
+                    "key %s already existed; Axes is being replaced" % key)
+            # I don't think the above should ever happen.
+
         if a in self:
             return None
         return Stack.push(self, (key, a))
@@ -648,15 +656,14 @@
 
         %(Axes)s
         """
+        if not len(args): return
 
         key = self._make_key(*args, **kwargs)
-
         ax = self._axstack.get(key)
         if ax is not None:
             self.sca(ax)
             return ax
 
-        if not len(args): return
         if isinstance(args[0], Axes):
             a = args[0]
             assert(a.get_figure() is self)
@@ -674,8 +681,7 @@
 
             a = projection_factory(projection, self, rect, **kwargs)
 
-        if a not in self._axstack:
-            self._axstack.add(key, a)
+        self._axstack.add(key, a)
         self.sca(a)
         return a
 
@@ -708,15 +714,17 @@
 
         %(Axes)s
         """
+        if not len(args): return
 
-        kwargs = kwargs.copy()
+        if len(args) == 1 and isinstance(args[0], int):
+            args = tuple([int(c) for c in str(args[0])])
 
-        if not len(args): return
-
         if isinstance(args[0], SubplotBase):
             a = args[0]
             assert(a.get_figure() is self)
+            key = self._make_key(*args, **kwargs)
         else:
+            kwargs = kwargs.copy()
             ispolar = kwargs.pop('polar', False)
             projection = kwargs.pop('projection', None)
             if ispolar:
@@ -729,6 +737,7 @@
 
             projection_class = get_projection_class(projection)
 
+            # Remake the key without projection kwargs:
             key = self._make_key(*args, **kwargs)
             ax = self._axstack.get(key)
             if ax is not None:
@@ -737,6 +746,11 @@
                     return ax
                 else:
                     self._axstack.remove(ax)
+                    # Undocumented convenience behavior:
+                    # subplot(111); subplot(111, projection='polar')
+                    # will replace the first with the second.
+                    # Without this, add_subplot would be simpler and
+                    # more similar to add_axes.
 
             a = subplot_class_factory(projection_class)(self, *args, **kwargs)
         self._axstack.add(key, a)


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