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

Last change on this file since 21243 was 19424, checked in by cborstad, 10 years ago

CHG: updates to python plotting routines

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