From: W. Trevor King Date: Fri, 27 Jan 2012 19:02:21 +0000 (-0500) Subject: Update plot_image.py's interpolation extraction for Matplotlib 0.91.2. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=78b87e47cbd6404e017bf7492df6b569ec03330c;p=parallel_computing.git Update plot_image.py's interpolation extraction for Matplotlib 0.91.2. 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). --- diff --git a/src/plot_image/plot_image.py b/src/plot_image/plot_image.py index 8c0a338..dd772a0 100755 --- a/src/plot_image/plot_image.py +++ b/src/plot_image/plot_image.py @@ -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))