Ignore:
Timestamp:
01/31/19 07:34:11 (6 years ago)
Author:
bdef
Message:

CHG: python scripts after 2to3 and indentation fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/py3/plot/plotmodel.py

    r21255 r23670  
    1 import numpy as np
     1import numpy as  np
    22from plotoptions import plotoptions
     3from plotdoc import plotdoc
     4from plot_manager import plot_manager
     5from math import ceil, sqrt
    36
    47try:
     
    69        import matplotlib.pyplot as plt
    710        from mpl_toolkits.axes_grid1 import ImageGrid, AxesGrid
     11        from mpl_toolkits.mplot3d import Axes3D
    812except ImportError:
    913        print("could not import pylab, matplotlib has not been installed, no plotting capabilities enabled")
    1014
    11 from plot_manager import plot_manager
    12 from math import ceil, sqrt
    13 
    1415def plotmodel(md,*args):
    15         '''
    16         at command prompt, type 'plotdoc' for additional documentation
     16        '''     at command prompt, type 'plotdoc()' for additional documentation
    1717        '''
    1818
    19         #First process options 
     19        #First process options
    2020        options=plotoptions(*args)
    2121
    2222        #get number of subplots
    2323        subplotwidth=ceil(sqrt(options.numberofplots))
    24        
    2524        #Get figure number and number of plots
    2625        figurenumber=options.figurenumber
     
    3736                nrows=np.ceil(numberofplots/subplotwidth)
    3837                nr=False
    39        
     38
    4039        if options.list[0].exist('ncols'):
    4140                ncols=options.list[0].getfieldvalue('ncols')
     
    4645        ncols=int(ncols)
    4746        nrows=int(nrows)
    48        
     47
    4948        #check that nrows and ncols were given at the same time!
    5049        if not nr==nc:
    5150                raise Exception('error: nrows and ncols need to be specified together, or not at all')
    52        
     51
    5352        #Go through plots
    5453        if numberofplots:
    55                
    5654                #if plt.fignum_exists(figurenumber):
    5755                #       plt.cla()
     
    6058                if options.list[0].exist('figsize'):
    6159                        figsize=options.list[0].getfieldvalue('figsize')
    62                         fig=plt.figure(figurenumber,figsize=(figsize[0],figsize[1]),tight_layout=True)
     60                        fig=plt.figure(figurenumber,figsize=(figsize[0],figsize[1]))#,tight_layout=True)
    6361                else:
    64                         fig=plt.figure(figurenumber,tight_layout=True)
     62                        fig=plt.figure(figurenumber)#,tight_layout=True)
    6563                fig.clf()
    6664
     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'}
    6772                # options needed to define plot grid
     73                plotnum=options.numberofplots
    6874                direction=options.list[0].getfieldvalue('direction','row') # row,column
    6975                axes_pad=options.list[0].getfieldvalue('axes_pad',0.25)
    7076                add_all=options.list[0].getfieldvalue('add_all',True) # True,False
    7177                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,
     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,
    7986                                nrows_ncols=(nrows,ncols),
     87                                ngrids=plotnum,
    8088                                direction=direction,
    8189                                axes_pad=axes_pad,
     
    8694                                cbar_location=cbar_location,
    8795                                cbar_size=cbar_size,
    88                                 cbar_pad=cbar_pad
    89                                 )
     96                                cbar_pad=cbar_pad)
    9097
    91                 if cbar_mode=='none':
    92                         for ax in axgrid.cbar_axes: fig._axstack.remove(ax)
     98                if cbar_mode=='None':
     99                        for ax in axgrid.cbar_axes:
     100                                fig._axstack.remove(ax)
    93101
    94                 for i in range(numberofplots):
    95                         plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid[i])
    96 
     102                for i,ax in enumerate(axgrid.axes_all):
     103                        plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid,i)
    97104                fig.show()
    98105        else:
Note: See TracChangeset for help on using the changeset viewer.