1 | try:
|
---|
2 | import pylab as p
|
---|
3 | except ImportError:
|
---|
4 | print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
|
---|
5 |
|
---|
6 | import numpy as np
|
---|
7 | from processmesh import processmesh
|
---|
8 | from applyoptions import applyoptions
|
---|
9 | from plot_icefront import plot_icefront
|
---|
10 |
|
---|
11 | def plot_elementnumbering(md,options,fig,axgrid,gridindex):
|
---|
12 | '''
|
---|
13 | plot_elementnumbering - plot element numberign (starting at 1 matlab and c convention)
|
---|
14 |
|
---|
15 | Usage:
|
---|
16 | plot_elementnumbering(md,options,fig,axes)
|
---|
17 |
|
---|
18 | See also: PLOTMODEL
|
---|
19 | '''
|
---|
20 | x,y,z,elements,is2d,isplanet=processmesh(md,[],options)
|
---|
21 |
|
---|
22 | ax=axgrid[gridindex]
|
---|
23 | fig.delaxes(axgrid.cbar_axes[gridindex])
|
---|
24 |
|
---|
25 | if is2d:
|
---|
26 | ax.triplot(x,y,elements)
|
---|
27 | else:
|
---|
28 | print 'Not Implemented Yet'
|
---|
29 |
|
---|
30 | XLims=[np.min(x),np.max(x)]
|
---|
31 | YLims=[np.min(y),np.max(y)]
|
---|
32 | #plot mesh
|
---|
33 | ax.triplot(x,y,elements)
|
---|
34 | highlightpos=options.getfieldvalue('highlight','none')
|
---|
35 | if highlightpos!='none':
|
---|
36 | #if just one element duplicate it to avoid coloring issues
|
---|
37 | if type(highlightpos)==int:
|
---|
38 | highlightpos=[highlightpos,highlightpos]
|
---|
39 | #convert from to matlab numbering
|
---|
40 | highlightpos=[pos-1 for pos in highlightpos]
|
---|
41 | colors=np.asarray([0.5 for element in elements[highlightpos]])
|
---|
42 | ax.tripcolor(x,y,elements[highlightpos],facecolors=colors,alpha=0.5)
|
---|
43 | # and numbers
|
---|
44 | for i,element in enumerate(elements):
|
---|
45 | ax.text(np.mean(x[element]),np.mean(y[element]),str(i+1),ha='center',va='center',clip_on=True)
|
---|
46 |
|
---|
47 | #apply options
|
---|
48 | options.addfielddefault('title','Element numbers (matlab indexation)')
|
---|
49 | options.addfielddefault('colorbar','off')
|
---|
50 | applyoptions(md,[],options,fig,axgrid,gridindex)
|
---|
51 |
|
---|