Update plot_image.py's interpolation extraction for Matplotlib 0.91.2.
authorW. Trevor King <wking@drexel.edu>
Fri, 27 Jan 2012 19:02:21 +0000 (14:02 -0500)
committerW. Trevor King <wking@tremily.us>
Fri, 22 Feb 2013 17:11:10 +0000 (09:11 -0800)
I'd written it for v1.0.1, but the department server is still running
0.91.2, which only sets the interpolation dictionary for AxesImage
instances (not for the class itself).

src/plot_image/plot_image.py

index 8c0a33806af9147b32fc0469a9cb4e57f7420266..dd772a0476c21d4d6cd8786666101956d27c1a46 100755 (executable)
@@ -174,6 +174,17 @@ def plot(X, Y, Z, full=False, title=None, contours=None, interpolation=None,
     return fig
 
 
+def get_possible_interpolations():
+    try:  # Matplotlib v1.0.1
+        return sorted(matplotlib.image.AxesImage._interpd.keys())
+    except AttributeError:
+        try:  # Matplotlib v0.91.2
+            return sorted(matplotlib.image.AxesImage(None)._interpd.keys())
+        except AttributeError:
+            # give up ;)
+            pass
+    return ['nearest']
+
 def test():
     import doctest
     results = doctest.testmod()
@@ -231,7 +242,7 @@ def main(argv=None):
                  help='Title (%default)')
     p.add_option('--test', dest='test', action='store_true',
                  help='Run internal tests and exit.')
-    interpolations = sorted(matplotlib.image.AxesImage._interpd.keys())
+    interpolations = get_possible_interpolations()
     p.add_option('--interpolation', dest='interpolation', default='nearest',
                  help=('Interpolation scheme (for false color images) from %s '
                        '(%%default)') % ', '.join(interpolations))