1 | from expread import expread
|
---|
2 | import numpy as np
|
---|
3 | from matplotlib.path import Path
|
---|
4 | import matplotlib.patches as patches
|
---|
5 |
|
---|
6 |
|
---|
7 | def 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)
|
---|