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
Line 
1import numpy as np
2from plotoptions import plotoptions
3from plotdoc import plotdoc
4from plot_manager import plot_manager
5from math import ceil, sqrt
6
7try:
8 import pylab as p
9 import matplotlib.pyplot as plt
10 from mpl_toolkits.axes_grid1 import ImageGrid, AxesGrid
11 from mpl_toolkits.mplot3d import Axes3D
12except ImportError:
13 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
14
15def plotmodel(md,*args):
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 #Get figure number and number of plots
25 figurenumber=options.figurenumber
26 numberofplots=options.numberofplots
27
28 #get hold
29 hold=options.list[0].getfieldvalue('hold',False)
30
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
35 else:
36 nrows=np.ceil(numberofplots/subplotwidth)
37 nr=False
38
39 if options.list[0].exist('ncols'):
40 ncols=options.list[0].getfieldvalue('ncols')
41 nc=True
42 else:
43 ncols=int(subplotwidth)
44 nc=False
45 ncols=int(ncols)
46 nrows=int(nrows)
47
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')
51
52 #Go through plots
53 if numberofplots:
54 #if plt.fignum_exists(figurenumber):
55 # plt.cla()
56
57 #if figsize specified
58 if options.list[0].exist('figsize'):
59 figsize=options.list[0].getfieldvalue('figsize')
60 fig=plt.figure(figurenumber,figsize=(figsize[0],figsize[1]))#,tight_layout=True)
61 else:
62 fig=plt.figure(figurenumber)#,tight_layout=True)
63 fig.clf()
64
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'}
72 # options needed to define plot grid
73 plotnum=options.numberofplots
74 direction=options.list[0].getfieldvalue('direction','row') # row,column
75 axes_pad=options.list[0].getfieldvalue('axes_pad',0.25)
76 add_all=options.list[0].getfieldvalue('add_all',True) # True,False
77 share_all=options.list[0].getfieldvalue('share_all',True) # True,False
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,
86 nrows_ncols=(nrows,ncols),
87 ngrids=plotnum,
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,
96 cbar_pad=cbar_pad)
97
98 if cbar_mode=='None':
99 for ax in axgrid.cbar_axes:
100 fig._axstack.remove(ax)
101
102 for i,ax in enumerate(axgrid.axes_all):
103 plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid,i)
104 fig.show()
105 else:
106 raise StandardError('plotmodel error message: no output data found.')
Note: See TracBrowser for help on using the repository browser.