old_contents: #!/usr/bin/env python
  
  import numpy as np
  import matplotlib.pyplot as plt
  import sys
  import getopt
  
  import mesh.patch as patch
  
  # plot a single variable from an output file
  #
  # Usage: ./plotvar.py filename variable
  
  def makeplot(myd, variable, outfile):
  
      plt.figure(num=1, figsize=(6.5,5.25), dpi=100, facecolor='w')
  
      var = myd.get_var(variable)
      myg = myd.grid
  
      img = plt.imshow(np.transpose(var.v()),
                         interpolation="nearest", origin="lower",
                         extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax])
  
      plt.colorbar()
  
      plt.xlabel("x")
      plt.ylabel("y")
  
      plt.savefig(outfile, bbox_inches="tight")
      plt.show()
  
  
  def usage():
      usage="""
  usage: plotvar.py [-h] [-o image.png] filename variable
  
  positional arguments:
    filename      required inputs: filename to read from
    variable      required inputs: variable to plot from filename
  
  optional arguments:
    -h, --help    show this help message and exit
    -o image.png  output image name. The extension .png will generate a PNG
                  file, .eps will generate an EPS file (default: plot.png).
  """
      print usage
      sys.exit()
  
  
  if __name__== "__main__":
  
      try: opts, next = getopt.getopt(sys.argv[1:], "o:h")
      except getopt.GetoptError:
          sys.exit("invalid calling sequence")
  
      outfile = "plot.png"
  
      for o, a in opts:
          if o == "-h": usage()
          if o == "-o": outfile = a
  
      try: file = next[0]
      except: usage()
  
      try: variable = next[1]
      except: usage()
  
      myg, myd = patch.read(file)
  
      makeplot(myd, variable, outfile)
  
new_contents: #!/usr/bin/env python
  
  import numpy as np
  import matplotlib.pyplot as plt
  import argparse
  
  import mesh.patch as patch
  
  # plot a single variable from an output file
  #
  # Usage: ./plotvar.py filename variable
  
  def makeplot(plotfile, variable, outfile):
  
      myg, myd = patch.read(plotfile)
  
      plt.figure(num=1, figsize=(6.5,5.25), dpi=100, facecolor='w')
  
      var = myd.get_var(variable)
  
      img = plt.imshow(np.transpose(var.v()),
                       interpolation="nearest", origin="lower",
                       extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax])
  
      plt.colorbar()
  
      plt.xlabel("x")
      plt.ylabel("y")
  
      plt.savefig(outfile, bbox_inches="tight")
      plt.show()
  
  
  def get_args():
  
      parser = argparse.ArgumentParser()
  
      parser.add_argument("-o", type=str, default="plot.png",
                          metavar="plot.png", help="output file name")
      parser.add_argument("plotfile", type=str, nargs=1,
                          help="the plotfile you wish to plot")
      parser.add_argument("variable", type=str, nargs=1,
                          help="the name of the solver used to run the simulation")
  
      args = parser.parse_args()
  
      return args
  
  if __name__== "__main__":
  
      args = get_args()
  
      makeplot(args.plotfile[0], args.variable[0], args.o)
  
subject: switch to argparse