Current SVN (r6540) raise an error for the following code.

import matplotlib.pyplot as plt
import matplotlib.axes as maxes

fig = plt.figure()
ax = maxes.Subplot(fig, 1, 1, 1)
fig.add_subplot(ax)



/Users/jjlee/.virtualenvs/default/lib/python2.5/site-packages/matplotlib/figure.pyc
in add_subplot(self, *args, **kwargs)
    687                 self._axstack.remove(ax)
    688
--> 689         a = subplot_class_factory(projection_class)(self,
*args, **kwargs)
    690         self.axes.append(a)
    691         self._axstack.push(a)

UnboundLocalError: local variable 'projection_class' referenced before
assignment


It seems that some of the code Mike recently introduced in "figure.py"
have incorrect indentation, but I'm not 100% sure.
I'm attaching a patch which seems to work for me, and It would be
great if Mike or others review it and apply.

-JJ
Index: lib/matplotlib/figure.py
===================================================================
--- lib/matplotlib/figure.py	(revision 6540)
+++ lib/matplotlib/figure.py	(working copy)
@@ -676,21 +676,21 @@
 
             projection_class = get_projection_class(projection)
 
-        key = self._make_key(*args, **kwargs)
-        if key in self._seen:
-            ax = self._seen[key]
-            if isinstance(ax, projection_class):
-                self.sca(ax)
-                return ax
-            else:
-                self.axes.remove(ax)
-                self._axstack.remove(ax)
+            key = self._make_key(*args, **kwargs)
+            if key in self._seen:
+                ax = self._seen[key]
+                if isinstance(ax, projection_class):
+                    self.sca(ax)
+                    return ax
+                else:
+                    self.axes.remove(ax)
+                    self._axstack.remove(ax)
 
-        a = subplot_class_factory(projection_class)(self, *args, **kwargs)
+            a = subplot_class_factory(projection_class)(self, *args, **kwargs)
+            self._seen[key] = a
         self.axes.append(a)
         self._axstack.push(a)
         self.sca(a)
-        self._seen[key] = a
         return a
     add_subplot.__doc__ = dedent(add_subplot.__doc__) % {
         'list': ", ".join(get_projection_names()),
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to