Changeset 21278


Ignore:
Timestamp:
10/17/16 02:01:09 (8 years ago)
Author:
cborstad
Message:

CHG: added capability to fill (patch) a closed contour using expdisp, and cleaned up function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/exp/expdisp.py

    r21276 r21278  
    11from expread import expread
    22import numpy as np
     3from matplotlib.path import Path
     4import matplotlib.patches as patches
    35
    46def expdisp(ax,options):
     
    1113
    1214    Usage:
    13         expdisp(domainoutline,ax)
     15        expdisp(ax,options)
    1416
    15     Example:
    16         expdisp('domain.exp',plt.gca(),linestyle='--k',linewidth=2,unitmultiplier=1.e3)
     17    List of options passable to plotmodel:
     18        'expdisp'      : path (or list of paths) to the exp file to be plotted
     19        'explinewidth' : linewidth
     20        'explinestyle' : matplotlib linestyle string
     21        'explinecolor' : matplotlib color string
     22        'expfill'      : (True/False) fill a closed contour
     23        'expfillcolor' : Color for a filled contour, only used if expfill is True
     24        'expfillalpha' : alpha transparency for filled contour
     25
     26    All options should be passed as lists of length len(number of exp files passed)
    1727    '''
    1828
    19     filename=options.getfieldvalue('expdisp')
    20     style=options.getfieldvalue('expstyle','k')
    21     linewidth=options.getfieldvalue('explinewidth',1)
     29    filenames=options.getfieldvalue('expdisp')
     30    linewidth=options.getfieldvalue('explinewidth',[1]*len(filenames))
     31    linestyle=options.getfieldvalue('explinestyle',['-']*len(filenames))
     32    linecolor=options.getfieldvalue('explinecolor',['k']*len(filenames))
     33    fill=options.getfieldvalue('expfill',[0]*len(filenames))
     34    alpha=options.getfieldvalue('expfillalpha',[1]*len(filenames))
     35    facecolor=options.getfieldvalue('expfillcolor',['r']*len(filenames))
    2236    unitmultiplier=options.getfieldvalue('unit',1)
    23     for i in xrange(len(filename)):
    24         filenamei=filename[i]
    25         stylei=style[i]
    26         if type(linewidth)==list:
    27             linewidthi=linewidth[i]
    28         else:
    29             linewidthi=linewidth
    30 
     37    for i in xrange(len(filenames)):
     38        linestylei=linestyle[i]
     39        linecolori=linecolor[i]
     40        linewidthi=linewidth[i]
     41        alphai=alpha[i]
     42        facecolori=facecolor[i]
     43        filenamei=filenames[i]
     44        filli=fill[i]
    3145        domain=expread(filenamei)
    32         for i in xrange(len(domain)):
    33             if domain[i]['nods']==1:
    34                 ax.plot(domain[i]['x']*unitmultiplier,domain[i]['y']*unitmultiplier,'o',mec='k',mfc='r',ms=10)
     46        for j in xrange(len(domain)):
     47            if domain[j]['nods']==1:
     48                ax.plot(domain[j]['x']*unitmultiplier,domain[j]['y']*unitmultiplier,'o',mec='k',mfc='r',ms=10)
     49            elif filli:
     50                verts=np.column_stack((domain[j]['x'],domain[j]['y']))
     51                codes=[Path.MOVETO] + [Path.LINETO]*(len(domain[j]['x'])-2) + [Path.CLOSEPOLY]
     52                path=Path(verts, codes)
     53                patch=patches.PathPatch(path,facecolor=facecolori,edgecolor=linecolori,alpha=alphai,
     54                        lw=linewidthi)
     55                ax.add_patch(patch)
    3556            else:
    36                 x=domain[i]['x'].tolist() # since expread returns a string representation of the arrays
    37                 y=domain[i]['y'].tolist()
    38                 ax.plot(x*unitmultiplier,y*unitmultiplier,stylei,linewidth=linewidthi)
     57                x=domain[j]['x'].tolist() # since expread returns a string representation of the arrays
     58                y=domain[j]['y'].tolist()
     59                ax.plot(x*unitmultiplier,y*unitmultiplier,ls=linestylei,lw=linewidthi,c=linecolori)
Note: See TracChangeset for help on using the changeset viewer.