Exemplo n.º 1
0
def surfacePlot(varlist, times=None, clevs=None,cbls=None,title='',axTitles=True,subplot=(),slices={},figargs={'figsize':(10,8)},**plotargs):
  import matplotlib.pylab as pyl
  from plotting.misc import multiPlot, sharedColorbar
  if not isinstance(varlist,list): varlist = [varlist]
  if not isinstance(times,list): times = [times]
  if not isinstance(clevs,list): clevs = [clevs]
  if not isinstance(cbls,list): cbls = [cbls]  
  pyl.ioff() # non-interactive mode
  # construct figure and axes    
  f = pyl.figure(**figargs)    
  f.clf()
  ## handle multiplot meta data
  if len(varlist)==1: 
    # plot single variable, possibly multiple times
    titles = []; plotlist = [];
    for time in times: 
      if time and axTitles: titles.append('time '+str(time))
      else: titles.append('')
      if varlist[0].hasaxis('time'): slices['time'] = time
      plotlist.append(varlist[0](**slices))
  else: 
    # plot multiple variables side-by-side, each time-step 
    if not subplot: subplot = (len(times),len(varlist))
    titles = []; plotlist = []; 
    for time in times:
      for var in varlist:
        if axTitles: titles.append(var.name+', time '+str(time))
        else: titles.append('')
        if var.hasaxis('time'): slices['time'] = time
        plotlist.append(var(**slices)) # sliced for time and latitude
  # expansion of other lists
  clevlist = clevs*len(times) # create contour level list for each plot
  cbllist = cbls*len(times) # create contour level list for each plot
  # organize colorbar (cleanup arguments) 
  colorbar = plotargs.pop('colorbar',{})
  manualCbar = colorbar.pop('manual',False)
  if manualCbar: cbar = False
  else: cbar = colorbar 
  # set default margins  
  defaultMargins = {'left':0.065,'right':0.975,'bottom':0.05,'top':0.95,'wspace':0.025,'hspace':0.1}
  defaultMargins.update(plotargs.pop('margins',{}))
  ## draw (sub-)plots  
  (f,cf,subplot) = multiPlot(f=f,varlist=plotlist,titles=titles,clevs=clevlist,cbls=cbllist, #
                     subplot=subplot,colorbar=cbar,margins=defaultMargins,**plotargs)  
  if title: f.suptitle(title,y=defaultMargins['top'],fontsize=plotargs.get('fontsize',12)+2) 
  ## add common colorbar
  if manualCbar:
    if len(varlist)==1: subplot = (1,1) # need only one colorbar, reference to first axes
    sharedColorbar(f, cf, clevs, colorbar, cbls, subplot, defaultMargins)   
  # finalize
  pyl.draw(); # pyl.ion(); 
  return f
Exemplo n.º 2
0
def surfacePlot(varlist, times=None, clevs=None,cbls=None,title='',axTitles=True,subplot=(),slices={},figargs={'figsize':(10,8)},**plotargs):
  import matplotlib.pylab as pyl
  from plotting.misc import multiPlot, sharedColorbar
  if not isinstance(varlist,list): varlist = [varlist]
  if not isinstance(times,list): times = [times]
  if not isinstance(clevs,list): clevs = [clevs]
  if not isinstance(cbls,list): cbls = [cbls]  
  pyl.ioff() # non-interactive mode
  # construct figure and axes    
  f = pyl.figure(**figargs)    
  f.clf()
  ## handle multiplot meta data
  if len(varlist)==1: 
    # plot single variable, possibly multiple times
    titles = []; plotlist = [];
    for time in times: 
      if time and axTitles: titles.append('time '+str(time))
      else: titles.append('')
      if varlist[0].hasaxis('time'): slices['time'] = time
      plotlist.append(varlist[0](**slices))
  else: 
    # plot multiple variables side-by-side, each time-step 
    if not subplot: subplot = (len(times),len(varlist))
    titles = []; plotlist = []; 
    for time in times:
      for var in varlist:
        if axTitles: titles.append(var.name+', time '+str(time))
        else: titles.append('')
        if var.hasaxis('time'): slices['time'] = time
        plotlist.append(var(**slices)) # sliced for time and latitude
  # expansion of other lists
  clevlist = clevs*len(times) # create contour level list for each plot
  cbllist = cbls*len(times) # create contour level list for each plot
  # organize colorbar (cleanup arguments) 
  colorbar = plotargs.pop('colorbar',{})
  manualCbar = colorbar.pop('manual',False)
  if manualCbar: cbar = False
  else: cbar = colorbar 
  # set default margins  
  defaultMargins = {'left':0.065,'right':0.975,'bottom':0.05,'top':0.95,'wspace':0.025,'hspace':0.1}
  defaultMargins.update(plotargs.pop('margins',{}))
  ## draw (sub-)plots  
  (f,cf,subplot) = multiPlot(f=f,varlist=plotlist,titles=titles,clevs=clevlist,cbls=cbllist, #
                     subplot=subplot,colorbar=cbar,margins=defaultMargins,**plotargs)  
  if title: f.suptitle(title,y=defaultMargins['top'],fontsize=plotargs.get('fontsize',12)+2) 
  ## add common colorbar
  if manualCbar:
    if len(varlist)==1: subplot = (1,1) # need only one colorbar, reference to first axes
    sharedColorbar(f, cf, clevs, colorbar, cbls, subplot, defaultMargins)   
  # finalize
  pyl.draw(); # pyl.ion(); 
  return f
Exemplo n.º 3
0
def hovmoellerPlot(varlist, clevs=None,cbls=None,title='',subplot=(),slices={},figargs={'figsize':(8,8)},**plotargs):
  import matplotlib.pylab as pyl    
  from pygeode.axis import XAxis, YAxis, TAxis
  from plotting.misc import multiPlot, sharedColorbar
  if not isinstance(varlist,list): varlist = [varlist]
  if not isinstance(clevs,list): clevs = [clevs]
  if not isinstance(cbls,list): cbls = [cbls]
  pyl.ioff() # non-interactive mode
  # construct figure and axes    
  f = pyl.figure(**figargs)    
  f.clf()
  # create zonal-mean variables
  titles = [var.name for var in varlist]
  plotlist = [var(**slices).mean(XAxis).transpose(YAxis,TAxis) for var in varlist] # latitude sliced
  # organize colorbar (cleanup arguments) 
  colorbar = plotargs.pop('colorbar',{})
  manualCbar = colorbar.pop('manual',False)
  if manualCbar: cbar = False
  else: cbar = colorbar 
  # set default margins  
  defaultMargins = {'left':0.065,'right':0.975,'bottom':0.05,'top':0.95,'wspace':0.05,'hspace':0.1}
  defaultMargins.update(plotargs.pop('margins',{}))
  ## make subplots
  (f,cf,subplot) = multiPlot(f=f,varlist=plotlist,titles=titles,clevs=clevs,cbls=cbls,subplot=subplot, #
                     colorbar=cbar,margins=defaultMargins,**plotargs)
  if title: f.suptitle(title,fontsize=14) 
  ## add common colorbar
  if manualCbar:
    f = sharedColorbar(f, cf, clevs, colorbar, cbls, subplot, defaultMargins)        
  # finalize
  pyl.draw(); # pyl.ion();
  return f
Exemplo n.º 4
0
def hovmoellerPlot(varlist, clevs=None,cbls=None,title='',subplot=(),slices={},figargs={'figsize':(8,8)},**plotargs):
  import matplotlib.pylab as pyl    
  from pygeode.axis import XAxis, YAxis, TAxis
  from plotting.misc import multiPlot, sharedColorbar
  if not isinstance(varlist,list): varlist = [varlist]
  if not isinstance(clevs,list): clevs = [clevs]
  if not isinstance(cbls,list): cbls = [cbls]
  pyl.ioff() # non-interactive mode
  # construct figure and axes    
  f = pyl.figure(**figargs)    
  f.clf()
  # create zonal-mean variables
  titles = [var.name for var in varlist]
  plotlist = [var(**slices).mean(XAxis).transpose(YAxis,TAxis) for var in varlist] # latitude sliced
  # organize colorbar (cleanup arguments) 
  colorbar = plotargs.pop('colorbar',{})
  manualCbar = colorbar.pop('manual',False)
  if manualCbar: cbar = False
  else: cbar = colorbar 
  # set default margins  
  defaultMargins = {'left':0.065,'right':0.975,'bottom':0.05,'top':0.95,'wspace':0.05,'hspace':0.1}
  defaultMargins.update(plotargs.pop('margins',{}))
  ## make subplots
  (f,cf,subplot) = multiPlot(f=f,varlist=plotlist,titles=titles,clevs=clevs,cbls=cbls,subplot=subplot, #
                     colorbar=cbar,margins=defaultMargins,**plotargs)
  if title: f.suptitle(title,fontsize=14) 
  ## add common colorbar
  if manualCbar:
    f = sharedColorbar(f, cf, clevs, colorbar, cbls, subplot, defaultMargins)        
  # finalize
  pyl.draw(); # pyl.ion();
  return f