1 | import numpy as npy
|
---|
2 | from plotoptions import plotoptions
|
---|
3 |
|
---|
4 | try:
|
---|
5 | import pylab as p
|
---|
6 | import matplotlib.pyplot as plt
|
---|
7 | from mpl_toolkits.axes_grid1 import ImageGrid, AxesGrid
|
---|
8 | except ImportError:
|
---|
9 | print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
|
---|
10 |
|
---|
11 | from plot_manager import plot_manager
|
---|
12 | from math import ceil, sqrt
|
---|
13 |
|
---|
14 | def 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.')
|
---|