[19421] | 1 | from expread import expread
|
---|
[21341] | 2 | import numpy as np
|
---|
| 3 | from matplotlib.path import Path
|
---|
| 4 | import matplotlib.patches as patches
|
---|
[19421] | 5 |
|
---|
[21341] | 6 | def expdisp(ax,options):
|
---|
[19421] | 7 | '''
|
---|
| 8 | plot the contents of a domain outline file
|
---|
| 9 |
|
---|
[21341] | 10 | This routine reads in an exp file and plots all of the x,y points/lines/patches
|
---|
[19421] | 11 |
|
---|
[21341] | 12 | 'ax' is a handle to the current plot axes, onto which we want to plot
|
---|
[19421] | 13 |
|
---|
| 14 | Usage:
|
---|
[21341] | 15 | expdisp(ax,options)
|
---|
[19421] | 16 |
|
---|
[21341] | 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)
|
---|
[19421] | 27 | '''
|
---|
| 28 |
|
---|
[21341] | 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))
|
---|
| 36 | unitmultiplier=options.getfieldvalue('unit',1)
|
---|
| 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]
|
---|
| 45 | domain=expread(filenamei)
|
---|
| 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)
|
---|
| 56 | else:
|
---|
| 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)
|
---|