Add --interpolation option to plot_image.py.
[parallel_computing.git] / src / plot_image / plot_image.py
index 591a7f4e64611de2f9cc9150daac3329e6fcab79..8c0a33806af9147b32fc0469a9cb4e57f7420266 100755 (executable)
@@ -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)