source: issm/branches/trunk-larour-NatGeoScience2016/src/m/plot/plotmodel.py@ 21759

Last change on this file since 21759 was 21759, checked in by Eric.Larour, 8 years ago

CHG: merged branch back to trunk-jpl 21754.

File size: 3.2 KB
RevLine 
[21759]1import numpy as np
[17502]2from plotoptions import plotoptions
[21759]3from plotdoc import plotdoc
4from plot_manager import plot_manager
5from math import ceil, sqrt
[13771]6
7try:
8 import pylab as p
[17778]9 import matplotlib.pyplot as plt
[19424]10 from mpl_toolkits.axes_grid1 import ImageGrid, AxesGrid
[21759]11 from mpl_toolkits.mplot3d import Axes3D
[13771]12except ImportError:
13 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
14
[13411]15def plotmodel(md,*args):
[21759]16 ''' at command prompt, type 'plotdoc()' for additional documentation
[13411]17 '''
18
[21759]19 #First process options
[13411]20 options=plotoptions(*args)
21
22 #get number of subplots
[13417]23 subplotwidth=ceil(sqrt(options.numberofplots))
[14260]24 #Get figure number and number of plots
25 figurenumber=options.figurenumber
26 numberofplots=options.numberofplots
27
[17617]28 #get hold
29 hold=options.list[0].getfieldvalue('hold',False)
30
[17778]31 #if nrows and ncols specified, then bypass
32 if options.list[0].exist('nrows'):
33 nrows=options.list[0].getfieldvalue('nrows')
34 nr=True
[13411]35 else:
[21759]36 nrows=np.ceil(numberofplots/subplotwidth)
[17778]37 nr=False
[21759]38
[13411]39 if options.list[0].exist('ncols'):
40 ncols=options.list[0].getfieldvalue('ncols')
41 nc=True
42 else:
[17819]43 ncols=int(subplotwidth)
[13411]44 nc=False
[17819]45 ncols=int(ncols)
46 nrows=int(nrows)
[21759]47
[17778]48 #check that nrows and ncols were given at the same time!
49 if not nr==nc:
50 raise StandardError('error: nrows and ncols need to be specified together, or not at all')
[21759]51
[13411]52 #Go through plots
53 if numberofplots:
[18194]54 #if plt.fignum_exists(figurenumber):
55 # plt.cla()
[17402]56
[13417]57 #if figsize specified
58 if options.list[0].exist('figsize'):
59 figsize=options.list[0].getfieldvalue('figsize')
[21759]60 fig=plt.figure(figurenumber,figsize=(figsize[0],figsize[1]))#,tight_layout=True)
[13417]61 else:
[21759]62 fig=plt.figure(figurenumber)#,tight_layout=True)
[17778]63 fig.clf()
[17822]64
[21759]65 backgroundcolor=options.list[0].getfieldvalue('backgroundcolor',(0.7,0.7,0.7))
66 fig.set_facecolor(backgroundcolor)
67
68
69 translator={'on':'each',
70 'off':'None',
71 'one':'single'}
[17822]72 # options needed to define plot grid
[21759]73 plotnum=options.numberofplots
[17822]74 direction=options.list[0].getfieldvalue('direction','row') # row,column
[17893]75 axes_pad=options.list[0].getfieldvalue('axes_pad',0.25)
[17822]76 add_all=options.list[0].getfieldvalue('add_all',True) # True,False
77 share_all=options.list[0].getfieldvalue('share_all',True) # True,False
[21759]78 label_mode=options.list[0].getfieldvalue('label_mode','L') # 1,L,all
79 colorbar=options.list[0].getfieldvalue('colorbar','on') # on, off (single)
80 cbar_mode=translator[colorbar]
81 cbar_location=options.list[0].getfieldvalue('colorbarpos','right') # right,top
82 cbar_size=options.list[0].getfieldvalue('colorbarsize','5%')
83 cbar_pad=options.list[0].getfieldvalue('colorbarpad','2.5%') # None or %
84
85 axgrid=ImageGrid(fig,111,
[17778]86 nrows_ncols=(nrows,ncols),
[21759]87 ngrids=plotnum,
[17822]88 direction=direction,
89 axes_pad=axes_pad,
90 add_all=add_all,
91 share_all=share_all,
92 label_mode=label_mode,
93 cbar_mode=cbar_mode,
94 cbar_location=cbar_location,
95 cbar_size=cbar_size,
[21759]96 cbar_pad=cbar_pad)
[17778]97
[21759]98 if cbar_mode=='None':
99 for ax in axgrid.cbar_axes:
100 fig._axstack.remove(ax)
[17841]101
[21759]102 for i,ax in enumerate(axgrid.axes_all):
103 plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid,i)
[17841]104 fig.show()
[13411]105 else:
106 raise StandardError('plotmodel error message: no output data found.')
Note: See TracBrowser for help on using the repository browser.