Index: /issm/trunk-jpl/src/m/plot/applyoptions.py
===================================================================
--- /issm/trunk-jpl/src/m/plot/applyoptions.py	(revision 17777)
+++ /issm/trunk-jpl/src/m/plot/applyoptions.py	(revision 17778)
@@ -8,10 +8,14 @@
 	import matplotlib as mpl
 	import pylab as p
+	import matplotlib.pyplot as plt
 except ImportError:
 	print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
 
-def applyoptions(md,data,options):
+def applyoptions(md,data,options,fig,ax):
 	'''
 	APPLYOPTIONS - apply options to current plot
+
+	'plotobj' is the object returned by the specific plot call used to
+	render the data.  This object is used for adding a colorbar.
 
 		Usage:
@@ -26,9 +30,9 @@
 
 	# get handle to current figure and axes instance
-	fig = p.gcf()
-	ax=p.gca()
+	#fig = p.gcf()
+	#ax=p.gca()
 
 	#font {{{
-	fontsize=options.getfieldvalue('fontsize',14)
+	fontsize=options.getfieldvalue('fontsize',8)
 	fontweight=options.getfieldvalue('fontweight','normal')
 	fontfamily=options.getfieldvalue('fontfamily','sans-serif')
@@ -55,5 +59,5 @@
 		titlefont['size']=titlefontsize
 		titlefont['weight']=titlefontweight
-		p.title(title,**titlefont)
+		fig.set_title(title,**titlefont)
 	#}}}
 		
@@ -74,9 +78,9 @@
 
 	if options.exist('xlabel'):
-		p.xlabel(options.getfieldvalue('xlabel'),**labelfont)
+		ax.set_xlabel(options.getfieldvalue('xlabel'),**labelfont)
 	if options.exist('ylabel'):
-		p.ylabel(options.getfieldvalue('ylabel'),**labelfont)
+		ax.set_ylabel(options.getfieldvalue('ylabel'),**labelfont)
 	if options.exist('zlabel'):
-		p.zlabel(options.getfieldvalue('zlabel'),**labelfont)
+		ax.set_zlabel(options.getfieldvalue('zlabel'),**labelfont)
 	#}}}
 
@@ -85,19 +89,19 @@
 		if options.exist('xticklabels'):
 			xticklabels=options.getfieldvalue('xticklabels')
-			p.xticks(options.getfieldvalue('xticks'),xticklabels)
-		else:
-			p.xticks(options.getfieldvalue('xticks'))
+			ax.set_xticks(options.getfieldvalue('xticks'),xticklabels)
+		else:
+			ax.set_xticks(options.getfieldvalue('xticks'))
 	if options.exist('yticks'):
 		if options.exist('yticklabels'):
 			yticklabels=options.getfieldvalue('yticklabels')
-			p.yticks(options.getfieldvalue('yticks'),yticklabels)
-		else:
-			p.yticks(options.getfieldvalue('yticks'))
+			ax.set_yticks(options.getfieldvalue('yticks'),yticklabels)
+		else:
+			ax.set_yticks(options.getfieldvalue('yticks'))
 	if options.exist('zticks'):
 		if options.exist('zticklabels'):
 			zticklabels=options.getfieldvalue('zticklabels')
-			p.zticks(options.getfieldvalue('zticks'),zticklabels)
-		else:
-			p.zticks(options.getfieldvalue('zticks'))
+			ax.set_zticks(options.getfieldvalue('zticks'),zticklabels)
+		else:
+			ax.set_zticks(options.getfieldvalue('zticks'))
 	#}}}
 
@@ -106,13 +110,13 @@
 		xticklabels=options.getfieldvalue('xticklabels')
 		xtickloc=p.xticks()[0]	
-		p.xticks(xtickloc,xticklabels)
+		ax.set_xticks(xtickloc,xticklabels)
 	if options.exist('yticklabels'):
 		yticklabels=options.getfieldvalue('yticklabels')
 		ytickloc=p.yticks()[0]	
-		p.yticks(ytickloc,yticklabels)
+		ax.set_yticks(ytickloc,yticklabels)
 	if options.exist('zticklabels'):
 		zticklabels=options.getfieldvalue('zticklabels')
 		ztickloc=p.zticks()[0]	
-		p.zticks(ztickloc,zticklabels)
+		ax.set_zticks(ztickloc,zticklabels)
 	#}}}
 
@@ -144,9 +148,9 @@
 	#xlim, ylim, zlim {{{
 	if options.exist('xlim'):
-		p.xlim(options.getfieldvalue('xlim'))
+		ax.set_xlim(options.getfieldvalue('xlim'))
 	if options.exist('ylim'):
-		p.ylim(options.getfieldvalue('ylim'))
+		ax.set_ylim(options.getfieldvalue('ylim'))
 	if options.exist('zlim'):
-		p.zlim(options.getfieldvalue('zlim'))
+		ax.set_zlim(options.getfieldvalue('zlim'))
 	#}}}
 
@@ -174,5 +178,5 @@
 	if options.exist('grid'):
 		if 'on' in options.getfieldvalue('grid','on'):
-			p.grid()
+			ax.grid()
 	#}}}
 
@@ -195,11 +199,13 @@
 	#}}}
 
+	#contours {{{
+	if options.exist('contourlevels'):
+		plot_contour(md,data,options,ax)
+	#}}}
+
 	#wrapping
 
 	#colorbar {{{
 	if options.getfieldvalue('colorbar',1)==1:
-		divider = make_axes_locatable(ax)
-		cax = divider.new_horizontal("5%", pad=0.05, axes_class=mpl.axes.Axes)
-		fig.add_axes(cax) 
 		if cbar_extend==0:
 			extend='neither'
@@ -210,10 +216,19 @@
 		elif cbar_extend==3:
 			extend='both'
-		cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm, extend=extend)
+		cb = mpl.colorbar.ColorbarBase(ax.cax, cmap=cmap, norm=norm, extend=extend)
 		cb.locator=MaxNLocator(nbins=5) # default 5 ticks
-		cb.update_ticks()
+		if options.exist('alpha'):
+			cb.set_alpha(options.getfieldvalue('alpha'))
 		if options.exist('colorbarnumticks'):
 			cb.locator=MaxNLocator(nbins=options.getfieldvalue('colorbarnumticks',5))
-			cb.update_ticks()
+		if options.exist('colorbartickspacing'):
+			locs=npy.arange(lims[0],lims[1]+1,options.getfieldvalue('colorbartickspacing'))
+			cb.set_ticks(locs)
+		if options.exist('colorbarlines'):
+			locs=npy.arange(lims[0],lims[1]+1,options.getfieldvalue('colorbarlines'))
+			cb.add_lines(locs,['k' for i in range(len(locs))],npy.ones_like(locs))
+		if options.exist('colorbartitle'):
+			cb.set_label(options.getfieldvalue('colorbartitle'),fontsize=fontsize)
+		cb.ax.tick_params(labelsize=fontsize)
 	#}}}
 
@@ -230,8 +245,4 @@
 	#streamlines
 
-	#contours {{{
-	if options.exist('contourlevels'):
-		plot_contour(md,data,options)
-	#}}}
 
 	#axis positions
Index: /issm/trunk-jpl/src/m/plot/plot_contour.py
===================================================================
--- /issm/trunk-jpl/src/m/plot/plot_contour.py	(revision 17777)
+++ /issm/trunk-jpl/src/m/plot/plot_contour.py	(revision 17778)
@@ -4,5 +4,5 @@
 from processdata import processdata
 
-def plot_contour(md,datain,options):
+def plot_contour(md,datain,options,ax):
 	'''
 	plot contours of a given field (called within plotmodel)
@@ -16,5 +16,4 @@
 	x,y,z,elements,is2d,isplanet=processmesh(md,datain,options)
 	data,datatype=processdata(md,datain,options)
-	ax=plt.gca()
 
 	# process data: must be on nodes
Index: /issm/trunk-jpl/src/m/plot/plot_manager.py
===================================================================
--- /issm/trunk-jpl/src/m/plot/plot_manager.py	(revision 17777)
+++ /issm/trunk-jpl/src/m/plot/plot_manager.py	(revision 17778)
@@ -1,4 +1,5 @@
 try:
 	import pylab as p
+	import matplotlib.pyplot as plt
 except ImportError:
 	print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
@@ -12,12 +13,17 @@
 from plot_overlay import plot_overlay
 
-def plot_manager(md,options,subplotwidth,nlines,ncols,i):
+def plot_manager(md,options,fig,ax):
 	'''
 	PLOT_MANAGER - distribute the plots called by plotmodel
 
-		Usage:
-			plot_manager(md,options,subplotwidth,i);
+	'fig' is a handle to the figure instance created by plotmodel.
 
-		See also: PLOTMODEL, PLOT_UNIT
+	'ax' is a handle to the axes instance created by plotmodel.  This is
+	currently generated using matplotlib's AxesGrid toolki.
+
+	Usage:
+		plot_manager(md,options,fig,ax);
+
+	See also: PLOTMODEL, PLOT_UNIT
 	'''
 
@@ -29,16 +35,16 @@
 
 	#initialize plot handle variable
-	handle=None
+	#handle=None
 
 	# initialize subplot
-	p.subplot(nlines,ncols,i,aspect='equal')
+	#p.subplot(nrows,ncols,i,aspect='equal')
 
 	##basemap plot
 	#if options.exist('basemap'):
-	#	plot_basemap(md,data,options,nlines,ncols,i)
+	#	plot_basemap(md,data,options,nrows,ncols,i)
 
 	#overlay plot
 	if options.exist('overlay'):
-		handle=plot_overlay(md,data,options,nlines,ncols,i)
+		plot_overlay(md,data,options,ax)
 		options.addfielddefault('alpha',0.5)
 		options.addfielddefault('xlim',[min(md.mesh.x),max(md.mesh.x)])
@@ -50,5 +56,5 @@
 		# convert string to lower case for a case-insensitive comparison
 		if data.lower()=='mesh': 
-			plot_mesh(md,options,nlines,ncols,i)
+			plot_mesh(md,options,ax)
 			return
 		elif data.lower()=='none':
@@ -74,11 +80,11 @@
 	#standard plot
 	#if not handle:
-	#	p.subplot(nlines,ncols,i,aspect='equal')
+	#	p.subplot(nrows,ncols,i,aspect='equal')
 
 	#plot unit
-	plot_unit(x,y,z,elements,data2,is2d,isplanet,datatype,options)
+	plot_unit(x,y,z,elements,data2,is2d,isplanet,datatype,options,ax)
 
 	#apply all options
-	applyoptions(md,data2,options)
+	applyoptions(md,data2,options,fig,ax)
 	
 	#ground overlay on kml plot_unit
Index: /issm/trunk-jpl/src/m/plot/plot_overlay.py
===================================================================
--- /issm/trunk-jpl/src/m/plot/plot_overlay.py	(revision 17777)
+++ /issm/trunk-jpl/src/m/plot/plot_overlay.py	(revision 17778)
@@ -7,5 +7,5 @@
 import os
 
-def plot_overlay(md,data,options,rows,cols,i):
+def plot_overlay(md,data,options,ax):
 	'''
 	Function for plotting a georeferenced image.  This function is called
@@ -76,5 +76,4 @@
 		plt.sca(ax) # return to original axes/figure
 		
-
 	# get parameters from cropped geotiff
 	trans=gtif.GetGeoTransform()
@@ -90,6 +89,5 @@
 	xg,yg=npy.meshgrid(xarr,yarr)
 	if options.exist('basemap'):
-		# TODO get handle to basemap instance 
-		# handle= functiontogethandle()
+		# TODO get handle to or create basemap instance 
 		# create coordinate grid in map projection units (for plotting)
 		lats,lons=xy2ll(xg,yg,-1,0,71)
@@ -98,5 +96,4 @@
 		xgmap=xg
 		ygmap=yg
-		handle=plt.gca()
 	
 	overlaylims=options.getfieldvalue('overlaylims',[min(arr.ravel()),max(arr.ravel())])
@@ -104,5 +101,3 @@
 	norm=mpl.colors.Normalize(vmin=overlaylims[0],vmax=overlaylims[1])
 
-	handle.pcolormesh(xgmap, ygmap, npy.flipud(arr), cmap=mpl.cm.Greys, norm=norm)
-	handle.set_aspect('equal','box')
-	return handle
+	ax.pcolormesh(xgmap, ygmap, npy.flipud(arr), cmap=mpl.cm.Greys, norm=norm)
Index: /issm/trunk-jpl/src/m/plot/plot_unit.py
===================================================================
--- /issm/trunk-jpl/src/m/plot/plot_unit.py	(revision 17777)
+++ /issm/trunk-jpl/src/m/plot/plot_unit.py	(revision 17778)
@@ -3,8 +3,9 @@
 	import pylab as p
 	import matplotlib as mpl
+	import matplotlib.pyplot as plt
 except ImportError:
 	print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
 
-def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options):
+def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,ax):
 	"""
 	PLOT_UNIT - unit plot, display data
@@ -46,15 +47,15 @@
 	   #element plot
 		if is2d:
-			p.tripcolor(x,y,elements,data,colorlevels,cmap=cmap,edgecolors=edgecolor)
+			tri=ax.tripcolor(x,y,elements,data,colorlevels,cmap=cmap,edgecolors=edgecolor)
 		else:
 			raise ValueError('plot_unit error: 3D element plot not supported yet')
-		return
+		return 
 	
 	elif datatype==2:
 		#node plot
 		if is2d:
-			p.tricontourf(x,y,elements,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha)
+			tri=ax.tricontourf(x,y,elements,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha)
 			if edgecolor != 'None':
-				p.triplot(x,y,elements,color=edgecolor)
+				ax.triplot(x,y,elements,color=edgecolor)
 		else:
 			raise ValueError('plot_unit error: 3D node plot not supported yet')
@@ -76,2 +77,3 @@
 	else:
 		raise ValueError('datatype=%d not supported' % datatype)
+
Index: /issm/trunk-jpl/src/m/plot/plotmodel.py
===================================================================
--- /issm/trunk-jpl/src/m/plot/plotmodel.py	(revision 17777)
+++ /issm/trunk-jpl/src/m/plot/plotmodel.py	(revision 17778)
@@ -4,4 +4,6 @@
 try:
 	import pylab as p
+	import matplotlib.pyplot as plt
+	from mpl_toolkits.axes_grid1 import ImageGrid
 except ImportError:
 	print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
@@ -28,11 +30,11 @@
 	hold=options.list[0].getfieldvalue('hold',False)
 
-	#if nlines and ncols specified, then bypass
-	if options.list[0].exist('nlines'):
-		nlines=options.list[0].getfieldvalue('nlines')
-		nl=True
+	#if nrows and ncols specified, then bypass
+	if options.list[0].exist('nrows'):
+		nrows=options.list[0].getfieldvalue('nrows')
+		nr=True
 	else:
-		nlines=npy.ceil(numberofplots/subplotwidth)
-		nl=False
+		nrows=npy.ceil(numberofplots/subplotwidth)
+		nr=False
 	
 	if options.list[0].exist('ncols'):
@@ -43,33 +45,40 @@
 		nc=False
 	
-	#check that nlines and ncols were given at the same time!
-	if not nl==nc:
-		raise StandardError('error: nlines and ncols need to be specified together, or not at all')
+	#check that nrows and ncols were given at the same time!
+	if not nr==nc:
+		raise StandardError('error: nrows and ncols need to be specified together, or not at all')
 	
 	#Go through plots
 	if numberofplots:
 		
-		#Create figure
-		#plots will be visible by default if ipython is run in interactive mode (invoked by ipython --pylab)
-		#UNLESS plotmodel is called within a script (e.g. a runme.py file) 
-		#handling the 'visible' option will need some check on whether ipython is currently in interactive or non-interactive mode
+		if not hold: # TODO need to also check whether figurenumber is a new plot so that old plots are not mistakenly cleared
+			plt.cla()
 
-		if not hold: # TODO need to also check whether figurenumber is a new plot so that old plots are not mistakenly cleared
-			p.cla()
-
-		#TODO fig, axarray = plt.subplots(nrows,ncols), then pass fix and axarr to plot_manager
 		#if figsize specified
 		if options.list[0].exist('figsize'):
 			figsize=options.list[0].getfieldvalue('figsize')
-			p.figure(figurenumber,figsize=figsize)
+			fig=plt.figure(figurenumber,figsize=figsize,tight_layout=True)
 		else:
-			p.figure(figurenumber)
-			
-		#try:
+			fig=plt.figure(figurenumber,tight_layout=True)
+		fig.clf()
+	
+		# options to pass: axes_pad, share_all, label_mode ("1","L","all"), cbar_mode (none,single,each), cbar_location(right,top)
+		axgrid=ImageGrid(fig, 111,
+				nrows_ncols=(nrows,ncols),
+				direction='row',
+				axes_pad=0.05,
+				add_all=True,
+				share_all=True,
+				label_mode='all',
+				cbar_mode='single',
+				cbar_location='right',
+				cbar_size='5%',
+				cbar_pad=0.05
+				)
+
 		for i in xrange(numberofplots):
-			plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],subplotwidth,nlines,ncols,i+1)
-		#except StandardError:
-		#	print 'error in plot_manager'
-		p.show()
+			plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid[i])
+
+		plt.show()
 	else:
 		raise StandardError('plotmodel error message: no output data found.')
