source: issm/trunk/src/m/exp/expdisp.py@ 28275

Last change on this file since 28275 was 24313, checked in by Mathieu Morlighem, 5 years ago

merged trunk-jpl and trunk for revision 24310

File size: 2.6 KB
Line 
1from expread import expread
2import numpy as np
3from matplotlib.path import Path
4import matplotlib.patches as patches
5
6
7def expdisp(ax, options):
8 '''
9 plot the contents of a domain outline file
10
11 This routine reads in an exp file and plots all of the x, y points / lines / patches
12
13 'ax' is a handle to the current plot axes, onto which we want to plot
14
15 Usage:
16 expdisp(ax, options)
17
18 List of options passable to plotmodel:
19 'expdisp' : path (or list of paths) to the exp file to be plotted
20 'explinewidth' : linewidth
21 'explinestyle' : matplotlib linestyle string
22 'explinecolor' : matplotlib color string
23 'expfill' : (True / False) fill a closed contour
24 'expfillcolor' : Color for a filled contour, only used if expfill is True
25 'expfillalpha' : alpha transparency for filled contour
26
27 All options should be passed as lists of length len(number of exp files passed)
28 '''
29
30 filenames = options.getfieldvalue('expdisp')
31 linewidth = options.getfieldvalue('explinewidth', [1] * len(filenames))
32 linestyle = options.getfieldvalue('explinestyle', ['-'] * len(filenames))
33 linecolor = options.getfieldvalue('explinecolor', ['k'] * len(filenames))
34 fill = options.getfieldvalue('expfill', [0] * len(filenames))
35 alpha = options.getfieldvalue('expfillalpha', [1] * len(filenames))
36 facecolor = options.getfieldvalue('expfillcolor', ['r'] * len(filenames))
37 unitmultiplier = options.getfieldvalue('unit', 1)
38 for i in range(len(filenames)):
39 linestylei = linestyle[i]
40 linecolori = linecolor[i]
41 linewidthi = linewidth[i]
42 alphai = alpha[i]
43 facecolori = facecolor[i]
44 filenamei = filenames[i]
45 filli = fill[i]
46 domain = expread(filenamei)
47 for j in range(len(domain)):
48 if domain[j]['nods'] == 1:
49 ax.plot(domain[j]['x'] * unitmultiplier, domain[j]['y'] * unitmultiplier, 'o', mec='k', mfc='r', ms=10)
50 elif filli:
51 verts = np.column_stack((domain[j]['x'], domain[j]['y']))
52 codes = [Path.MOVETO] + [Path.LINETO] * (len(domain[j]['x']) - 2) + [Path.CLOSEPOLY]
53 path = Path(verts, codes)
54 patch = patches.PathPatch(path, facecolor=facecolori, edgecolor=linecolori, alpha=alphai,
55 lw=linewidthi)
56 ax.add_patch(patch)
57 else:
58 x = domain[j]['x'].tolist() # since expread returns a string representation of the arrays
59 y = domain[j]['y'].tolist()
60 ax.plot(x * unitmultiplier, y * unitmultiplier, ls=linestylei, lw=linewidthi, c=linecolori)
Note: See TracBrowser for help on using the repository browser.