From: W. Trevor King Date: Sat, 21 Jan 2012 19:17:12 +0000 (-0500) Subject: Add --interpolation option to plot_image.py. X-Git-Url: http://git.tremily.us/?p=parallel_computing.git;a=commitdiff_plain;h=bf8376edb0f521f1a8ed654b1ac757484d591449 Add --interpolation option to plot_image.py. --- diff --git a/src/plot_image/plot_image.py b/src/plot_image/plot_image.py index 591a7f4..8c0a338 100755 --- a/src/plot_image/plot_image.py +++ b/src/plot_image/plot_image.py @@ -54,11 +54,12 @@ For other ideas, see the Matplotlib website [2]_. import optparse import sys +import matplotlib +import matplotlib.image import numpy # Depending on your Matplotlib configuration, you may need to adjust # your backend. Do this before importing pylab or matplotlib.backends. -#import matplotlib #matplotlib.use('Agg') # select backend that doesn't require X Windows #matplotlib.use('GTKAgg') # select backend that supports pylab.show() @@ -134,7 +135,8 @@ def read_data_3d(stream): X,Y = pylab.meshgrid(Xs, Ys) return (X,Y,Z) -def plot(X, Y, Z, full=False, title=None, contours=None, cmap=None): +def plot(X, Y, Z, full=False, title=None, contours=None, interpolation=None, + cmap=None): """Plot Z over the mesh X, Y. >>> X, Y = pylab.meshgrid(range(6), range(2)) @@ -164,7 +166,7 @@ def plot(X, Y, Z, full=False, title=None, contours=None, cmap=None): # pcolor() is much slower than imshow. #plot = axes.pcolor(X, Y, Z, cmap=cmap, edgecolors='none') #axes.autoscale_view(tight=True) - plot = axes.imshow(Z, aspect='auto', interpolation='bilinear', + plot = axes.imshow(Z, aspect='auto', interpolation=interpolation, origin='lower', cmap=cmap, extent=(X_min, X_max, Y_min, Y_max)) if not full: @@ -229,6 +231,10 @@ 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()) + p.add_option('--interpolation', dest='interpolation', default='nearest', + help=('Interpolation scheme (for false color images) from %s ' + '(%%default)') % ', '.join(interpolations)) maps=[m for m in pylab.cm.datad if not m.endswith("_r")] maps.sort() p.add_option('-m', '--color-map', dest='cmap', default='jet', @@ -274,7 +280,8 @@ def main(argv=None): print 'Z range: ', Z_min, Z_max fig = plot(X, Y, Z, full=options.full, title=options.title, - contours=options.contours, cmap=cmap) + contours=options.contours, interpolation=options.interpolation, + cmap=cmap) if options.output: fig.savefig(options.output)