Changeset 21440
- Timestamp:
- 12/14/16 03:36:13 (8 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plot_manager.py
r21355 r21440 24 24 from plot_overlay import plot_overlay 25 25 26 def plot_manager(md,options,fig,ax ):26 def plot_manager(md,options,fig,axgrid,gridindex): 27 27 ''' 28 28 PLOT_MANAGER - distribute the plots called by plotmodel … … 46 46 options.addfielddefault('ticklabels','on') 47 47 48 ax=axgrid[gridindex] 48 49 # {{{ basemap plot TOFIX 49 50 #if options.exist('basemap'): … … 60 61 if isinstance(data,(str,unicode)): 61 62 if data=='mesh': 62 plot_mesh(md,options,fig,ax) 63 plot_mesh(md,options,fig,axgrid,gridindex) 64 63 65 #fig.delaxes(fig.axes[1]) # hack to remove colorbar after the fact 64 66 return -
issm/trunk-jpl/src/m/plot/plot_mesh.py
r21283 r21440 3 3 except ImportError: 4 4 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled" 5 5 import numpy as np 6 import matplotlib as mpl 6 7 from processmesh import processmesh 7 8 from applyoptions import applyoptions 8 9 def plot_mesh(md,options,fig,ax): 9 from matplotlib.patches import Polygon 10 from mpl_toolkits.mplot3d.art3d import Line3DCollection 11 def plot_mesh(md,options,fig,axgrid,gridindex): 10 12 ''' 11 13 PLOT_MESH - plot model mesh … … 16 18 See also: PLOTMODEL 17 19 ''' 20 x,y,z,elements,is2d,isplanet=processmesh(md,'mesh',options) 18 21 19 x,y,z,elements,is2d,isplanet=processmesh(md,[],options) 20 22 ax=axgrid[gridindex] 23 fig.delaxes(axgrid.cbar_axes[gridindex]) 24 21 25 if is2d: 22 26 ax.triplot(x,y,elements) 23 27 else: 24 print 'WARNING: only 2D mesh plot is currently implemented' 25 28 fig.delaxes(ax) 29 geom=int(str(axgrid.get_geometry()[0])+str(axgrid.get_geometry()[1])+str(gridindex+1)) 30 ax = fig.add_subplot(geom,projection='3d') 31 32 AB=elements[:,0:2] 33 BC=elements[:,1:3] 34 CA=np.vstack((elements[:,2],elements[:,0])).T 35 DE=elements[:,3:5] 36 EF=elements[:,4:] 37 FD=np.vstack((elements[:,5],elements[:,3])).T 38 AD=np.vstack((elements[:,0],elements[:,3])).T 39 BE=np.vstack((elements[:,1],elements[:,4])).T 40 CF=np.vstack((elements[:,2],elements[:,5])).T 41 42 tmpa=np.vstack((AB,BC,CA,DE,EF,FD,AD,BE,CF)) 43 #deleting segments that appear multiple times 44 tmpb = np.ascontiguousarray(tmpa).view(np.dtype((np.void, tmpa.dtype.itemsize * tmpa.shape[1]))) 45 _, idx = np.unique(tmpb, return_index=True) 46 triel= tmpa[idx] 47 48 for triangle in triel: 49 tri=zip(x[triangle],y[triangle],z[triangle]) 50 pl3=Line3DCollection([tri],edgecolor='r') 51 ax.add_collection3d(pl3) 52 53 ax.set_xlim([min(x),max(x)]) 54 ax.set_ylim([min(y),max(y)]) 55 ax.set_zlim([min(z),max(z)]) 26 56 #apply options 27 57 options.addfielddefault('title','Mesh') -
issm/trunk-jpl/src/m/plot/plotmodel.py
r21426 r21440 2 2 from plotoptions import plotoptions 3 3 from plotdoc import plotdoc 4 from plot_manager import plot_manager 5 from math import ceil, sqrt 4 6 5 7 try: 6 8 import pylab as p 7 9 import matplotlib.pyplot as plt 8 from mpl_toolkits.axes_grid1 import ImageGrid, AxesGrid 10 from mpl_toolkits.axes_grid1 import ImageGrid, AxesGrid 11 from mpl_toolkits.mplot3d import Axes3D 9 12 except ImportError: 10 13 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled" 11 12 from plot_manager import plot_manager13 from math import ceil, sqrt14 14 15 15 def plotmodel(md,*args): … … 83 83 cbar_pad=options.list[0].getfieldvalue('colorbarpad','2.5%') # None or % 84 84 85 axgrid=ImageGrid(fig, 85 axgrid=ImageGrid(fig,111, 86 86 nrows_ncols=(nrows,ncols), 87 87 ngrids=plotnum, … … 94 94 cbar_location=cbar_location, 95 95 cbar_size=cbar_size, 96 cbar_pad=cbar_pad 97 ) 96 cbar_pad=cbar_pad) 98 97 99 98 if cbar_mode=='None': … … 101 100 fig._axstack.remove(ax) 102 101 103 for i in xrange(numberofplots): 104 plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid[i]) 105 102 for i,ax in enumerate(axgrid.axes_all): 103 plot_manager(options.list[i].getfieldvalue('model',md),options.list[i],fig,axgrid,i) 106 104 fig.show() 107 105 else: -
issm/trunk-jpl/src/m/plot/processmesh.py
r21427 r21440 15 15 if md.mesh.numberofvertices==0: 16 16 raise ValueError('processmesh error: mesh is empty') 17 18 17 if md.mesh.numberofvertices==md.mesh.numberofelements: 18 raise ValueError('processmesh error: the number of elements is the same as the number of nodes') 19 19 # }}} 20 # {{{ treating non data plots mesh 21 if len(data)==0 or not isinstance(data,dict): 22 if 'latlon' not in options.getfieldvalue('coord','xy').lower(): #convert to lower case for comparison 23 try: 24 x=md.mesh.x2d 25 except AttributeError: 26 x=md.mesh.x 27 try: 28 y=md.mesh.y2d 29 except AttributeError: 30 y=md.mesh.y 31 else: 32 x=md.mesh.long 33 y=md.mesh.lat 34 try: 35 z=md.mesh.z 36 except AttributeError: 37 z=np.zeros_like(md.mesh.x) 20 # {{{ treating coordinates 21 22 try: 23 z=md.mesh.z 24 except AttributeError: 25 z=np.zeros(np.shape(md.mesh.x)) 26 elements=md.mesh.elements-1 27 28 if options.getfieldvalue('layer',0)>=1: 29 x=md.mesh.x2d 30 y=md.mesh.y2d 31 z=np.zeros(np.shape(x)) 32 elements=md.mesh.elements2d-1 33 elif 'latlon' in options.getfieldvalue('coord','xy'): 34 x=md.mesh.long 35 y=md.mesh.lat 36 else: 37 x=md.mesh.x 38 y=md.mesh.y 39 40 #is it a 2D plot? 41 if md.mesh.dimension()==2 or options.getfieldvalue('layer',0)>=1: 42 is2d=1 43 else: 44 is2d=0 38 45 39 try:40 elements=md.mesh.elements2d-141 except AttributeError:42 elements=md.mesh.elements-143 44 #is it a 2D plot?45 if md.mesh.dimension()==2 or options.getfieldvalue('layer',0)>=1:46 is2d=147 else:48 is2d=049 50 #layer projection?51 if options.getfieldvalue('layer',0)>=1:52 if 'latlon' in options.getfieldvalue('coord','xy').lower():53 raise ValueError('processmesh error: cannot work with 3D mesh in lat-lon coords')54 #we modify the mesh temporarily to a 2D mesh from which the 3D mesh was extruded55 z=np.zeros(np.size(x))56 elements=elements57 else:58 #Process mesh for plotting59 if md.mesh.dimension()==2:60 is2d=161 else:62 # process polycollection here for 3D plot63 is2d=064 46 #units 65 47 if options.exist('unit'):
Note:
See TracChangeset
for help on using the changeset viewer.