Changeset 26182


Ignore:
Timestamp:
04/08/21 03:48:03 (4 years ago)
Author:
bdef
Message:

CHG: better subplot handling

File:
1 edited

Legend:

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

    r25125 r26182  
    1414def plotmodel(md, *args):
    1515    '''
    16     PLOTMODEL - At command prompt, type 'plotdoc()' for additional 
     16    PLOTMODEL - At command prompt, type 'plotdoc()' for additional
    1717    documentation.
    1818
     
    3131    subplotwidth = ceil(sqrt(numberofplots))
    3232
    33     # TODO: Check that commenting this out is correct; we do not need a hold 
     33    # TODO: Check that commenting this out is correct; we do not need a hold
    3434    # under matplotlib, right?
    3535    #
     
    4040    if options.list[0].exist('nrows'):
    4141        nrows = options.list[0].getfieldvalue('nrows')
    42         nr = True
    4342    else:
    44         nrows = np.ceil(numberofplots / subplotwidth)
    45         nr = False
     43        if options.list[0].exist('ncols'):
     44            ncols = options.list[0].getfieldvalue('ncols')
     45            nrows = np.ceil(numberofplots / ncols)
     46        else:
     47            nrows = np.ceil(numberofplots / subplotwidth)
    4648
    4749    if options.list[0].exist('ncols'):
    4850        ncols = options.list[0].getfieldvalue('ncols')
    49         nc = True
     51        nrows = np.ceil(numberofplots / ncols)
    5052    else:
    5153        ncols = int(subplotwidth)
    52         nc = False
    5354    ncols = int(ncols)
    5455    nrows = int(nrows)
    5556
    56     #check that nrows and ncols were given at the same time!
    57     if nr != nc:
    58         raise Exception('plotmodel error message: nrows and ncols need to be specified together, or not at all')
    59 
    6057    # Go through plots
    6158    #
    62     # NOTE: The following is where Python + matplolib differs substantially in 
     59    # NOTE: The following is where Python + matplolib differs substantially in
    6360    #       implementation and inteface from MATLAB.
    6461    #
     
    8380            plotnum = None
    8481
    85         # NOTE: The inline comments for each of the following parameters are 
     82        # NOTE: The inline comments for each of the following parameters are
    8683        #       taken from https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.axes_grid.ImageGrid.html
    8784        #
    88         direction = options.list[0].getfieldvalue('direction', 'row') # {"row", "column"}, default: "row"
    89         axes_pad = options.list[0].getfieldvalue('axes_pad', 0.25) # float or (float, float), default : 0.02; Padding or (horizonal padding, vertical padding) between axes, in inches
    90         add_all = options.list[0].getfieldvalue('add_all', True) # bool, default: True
    91         share_all = options.list[0].getfieldvalue('share_all', True) # bool, default: False
    92         label_mode = options.list[0].getfieldvalue('label_mode', 'L') # {"L", "1", "all"}, default: "L"; Determines which axes will get tick labels: "L": All axes on the left column get vertical tick labels; all axes on the bottom row get horizontal tick labels;. "1": Only the bottom left axes is labelled. "all": all axes are labelled.
     85        direction = options.list[0].getfieldvalue('direction', 'row')  # {"row", "column"}, default: "row"
     86        axes_pad = options.list[0].getfieldvalue('axes_pad', 0.25)  # float or (float, float), default : 0.02; Padding or (horizonal padding, vertical padding) between axes, in inches
     87        add_all = options.list[0].getfieldvalue('add_all', True)  # bool, default: True
     88        share_all = options.list[0].getfieldvalue('share_all', True)  # bool, default: False
     89        label_mode = options.list[0].getfieldvalue('label_mode', 'L')  # {"L", "1", "all"}, default: "L"; Determines which axes will get tick labels: "L": All axes on the left column get vertical tick labels; all axes on the bottom row get horizontal tick labels;. "1": Only the bottom left axes is labelled. "all": all axes are labelled.
    9390
    9491        # Translate MATLAB colorbar mode to matplotlib
    9592        #
    9693        # TODO:
    97         # - Add 'edge' option (research if there is a corresponding option in 
     94        # - Add 'edge' option (research if there is a corresponding option in
    9895        #   MATLAB)?
    9996        #
     
    109106            raise RuntimeError('plotmodel error: colorbar mode \'{}\' is not a valid option'.format(colorbar))
    110107
    111         cbar_mode = colorbar # {"each", "single", "edge", None }, default: None
    112         cbar_location = options.list[0].getfieldvalue('colorbarpos', 'right') # {"left", "right", "bottom", "top"}, default: "right"
    113         cbar_pad = options.list[0].getfieldvalue('colorbarpad', 0.025) # float, default: None
    114         cbar_size = options.list[0].getfieldvalue('colorbarsize', '5%') # size specification (see Size.from_any), default: "5%"
     108        cbar_mode = colorbar   # {"each", "single", "edge", None }, default: None
     109        cbar_location = options.list[0].getfieldvalue('colorbarpos', 'right')   # {"left", "right", "bottom", "top"}, default: "right"
     110        cbar_pad = options.list[0].getfieldvalue('colorbarpad', 0.025)  # float, default: None
     111        cbar_size = options.list[0].getfieldvalue('colorbarsize', '5%')  # size specification (see Size.from_any), default: "5%"
    115112
    116113        # NOTE: Second parameter is:
     
    118115        #   rect(float, float, float, float) or int
    119116        #
    120         # The axes position, as a (left, bottom, width, height) tuple or as a 
     117        # The axes position, as a (left, bottom, width, height) tuple or as a
    121118        # three-digit subplot position code (e.g., "121").
    122119        #
Note: See TracChangeset for help on using the changeset viewer.