Changeset 21444
- Timestamp:
- 12/15/16 03:14:02 (8 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/applyoptions.py
r21435 r21444 10 10 from mpl_toolkits.mplot3d import Axes3D 11 11 import matplotlib as mpl 12 import pylab as p13 12 import matplotlib.pyplot as plt 14 13 except ImportError: 15 14 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled" 16 15 17 def applyoptions(md,data,options,fig,ax ):16 def applyoptions(md,data,options,fig,axgrid,gridindex): 18 17 ''' 19 18 APPLYOPTIONS - apply options to current plot … … 30 29 # get handle to current figure and axes instance 31 30 #fig = p.gcf() 32 #ax=p.gca()31 ax= axgrid[gridindex] 33 32 34 33 # {{{ font -
issm/trunk-jpl/src/m/plot/plot_manager.py
r21442 r21444 93 93 data2,datatype=processdata(md,data,options) 94 94 #plot unit 95 plot_unit(x,y,z,elements,data2,is2d,isplanet,datatype,options, ax)95 plot_unit(x,y,z,elements,data2,is2d,isplanet,datatype,options,fig,axgrid,gridindex) 96 96 #apply all options 97 applyoptions(md,data2,options,fig,ax )97 applyoptions(md,data2,options,fig,axgrid,gridindex) 98 98 99 99 #ground overlay on kml plot_unit -
issm/trunk-jpl/src/m/plot/plot_mesh.py
r21440 r21444 9 9 from matplotlib.patches import Polygon 10 10 from mpl_toolkits.mplot3d.art3d import Line3DCollection 11 from mpl_toolkits.axes_grid1 import inset_locator 12 from mpl_toolkits.mplot3d import Axes3D 11 13 def plot_mesh(md,options,fig,axgrid,gridindex): 12 14 ''' … … 25 27 if is2d: 26 28 ax.triplot(x,y,elements) 29 27 30 else: 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 31 # fig.delaxes(ax) 32 # geom=int(str(axgrid.get_geometry()[0])+str(axgrid.get_geometry()[1])+str(gridindex+1)) 33 # ax = fig.add_subplot(geom,projection='3d') 34 ax=inset_locator.inset_axes(axgrid[gridindex],width='100%',height='100%',loc=3,borderpad=0,axes_class=Axes3D) 35 36 32 37 AB=elements[:,0:2] 33 38 BC=elements[:,1:3] … … 39 44 BE=np.vstack((elements[:,1],elements[:,4])).T 40 45 CF=np.vstack((elements[:,2],elements[:,5])).T 41 46 42 47 tmpa=np.vstack((AB,BC,CA,DE,EF,FD,AD,BE,CF)) 43 48 #deleting segments that appear multiple times … … 50 55 pl3=Line3DCollection([tri],edgecolor='r') 51 56 ax.add_collection3d(pl3) 52 57 53 58 ax.set_xlim([min(x),max(x)]) 54 59 ax.set_ylim([min(y),max(y)]) … … 58 63 options.addfielddefault('colorbar','off') 59 64 options.addfielddefault('ticklabels','on') 60 applyoptions(md,[],options,fig,ax )65 applyoptions(md,[],options,fig,axgrid,gridindex) -
issm/trunk-jpl/src/m/plot/plot_unit.py
r21427 r21444 1 1 from cmaptools import truncate_colormap 2 2 from plot_quiver import plot_quiver 3 import numpy as np 3 4 try: 4 import pylab as p5 5 import matplotlib as mpl 6 6 import matplotlib.pyplot as plt 7 import numpy as np 7 from mpl_toolkits.axes_grid1 import inset_locator 8 from mpl_toolkits.mplot3d import Axes3D 9 from mpl_toolkits.mplot3d.art3d import Poly3DCollection 8 10 except ImportError: 9 11 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled" 10 12 11 def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options, ax):13 def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,fig,axgrid,gridindex): 12 14 """ 13 15 PLOT_UNIT - unit plot, display data … … 18 20 See also: PLOTMODEL, PLOT_MANAGER 19 21 """ 20 22 #if we are plotting 3d replace the current axis 23 if not is2d: 24 ax=inset_locator.inset_axes(axgrid[gridindex],width='100%',height='100%',loc=3,borderpad=0,axes_class=Axes3D) 25 else: 26 ax=axgrid[gridindex] 27 21 28 #edgecolor 22 29 edgecolor=options.getfieldvalue('edgecolor','None') … … 42 49 options.addfield('colormap',cmap) 43 50 # }}} 44 # {{{ if plotting only one of several layers reduce dataset 51 # {{{ if plotting only one of several layers reduce dataset, same for surface 45 52 if options.getfieldvalue('layer',0)>=1: 46 plotlayer=options.getfieldvalue('layer', 1)53 plotlayer=options.getfieldvalue('layer',0) 47 54 if datatype==1: 48 55 slicesize=np.shape(elements)[0] … … 84 91 tri=ax.tripcolor(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,edgecolors=edgecolor) 85 92 else: 86 raise ValueError('plot_unit error: 3D element plot not supported yet') 93 #first deal with colormap 94 loccmap = plt.cm.ScalarMappable(cmap=cmap) 95 loccmap.set_array([min(data),max(data)]) 96 loccmap.set_clim(vmin=min(data),vmax=max(data)) 97 98 #dealing with prism sides 99 recface=np.vstack((elements[:,0],elements[:,1],elements[:,4],elements[:,3])).T 100 eltind=np.arange(0,np.shape(elements)[0]) 101 recface=np.vstack((recface,np.vstack((elements[:,1],elements[:,2],elements[:,5],elements[:,4])).T)) 102 eltind=np.hstack((eltind,np.arange(0,np.shape(elements)[0]))) 103 recface=np.vstack((recface,np.vstack((elements[:,2],elements[:,0],elements[:,3],elements[:,5])).T)) 104 eltind=np.hstack((eltind,np.arange(0,np.shape(elements)[0]))) 105 tmp = np.ascontiguousarray(recface).view(np.dtype((np.void, recface.dtype.itemsize * recface.shape[1]))) 106 _, idx = np.unique(tmp, return_index=True) 107 recel= recface[idx] 108 recindex=eltind[idx] 109 for i,rectangle in enumerate(recel): 110 rec=zip(x[rectangle],y[rectangle],z[rectangle]) 111 pl3=Poly3DCollection([rec]) 112 color=loccmap.to_rgba(data[recindex[i]]) 113 pl3.set_edgecolor(color) 114 pl3.set_color(color) 115 ax.add_collection3d(pl3) 116 117 #dealing with prism bases 118 triface=np.vstack((elements[:,0:3],elements[:,3:6])) 119 eltind=np.arange(0,np.shape(elements)[0]) 120 eltind=np.hstack((eltind,np.arange(0,np.shape(elements)[0]))) 121 tmp = np.ascontiguousarray(triface).view(np.dtype((np.void, triface.dtype.itemsize * triface.shape[1]))) 122 _, idx = np.unique(tmp, return_index=True) 123 triel= triface[idx] 124 triindex=eltind[idx] 125 for i,triangle in enumerate(triel): 126 tri=zip(x[triangle],y[triangle],z[triangle]) 127 pl3=Poly3DCollection([tri]) 128 color=loccmap.to_rgba(data[triindex[i]]) 129 pl3.set_edgecolor(color) 130 pl3.set_color(color) 131 ax.add_collection3d(pl3) 132 133 ax.set_xlim([min(x),max(x)]) 134 ax.set_ylim([min(y),max(y)]) 135 ax.set_zlim([min(z),max(z)]) 136 137 #raise ValueError('plot_unit error: 3D element plot not supported yet') 87 138 return 88 139 # }}} … … 99 150 ax.triplot(x,y,elements,color=edgecolor) 100 151 else: 101 raise ValueError('plot_unit error: 3D node plot not supported yet') 152 #first deal with the colormap 153 loccmap = plt.cm.ScalarMappable(cmap=cmap) 154 loccmap.set_array([min(data),max(data)]) 155 loccmap.set_clim(vmin=min(data),vmax=max(data)) 156 157 #deal with prism sides 158 recface=np.vstack((elements[:,0],elements[:,1],elements[:,4],elements[:,3])).T 159 recface=np.vstack((recface,np.vstack((elements[:,1],elements[:,2],elements[:,5],elements[:,4])).T)) 160 recface=np.vstack((recface,np.vstack((elements[:,2],elements[:,0],elements[:,3],elements[:,5])).T)) 161 tmp = np.ascontiguousarray(recface).view(np.dtype((np.void, recface.dtype.itemsize * recface.shape[1]))) 162 _, idx = np.unique(tmp, return_index=True) 163 recel= recface[idx] 164 for rectangle in recel: 165 rec=zip(x[rectangle],y[rectangle],z[rectangle]) 166 pl3=Poly3DCollection([rec]) 167 color=loccmap.to_rgba(np.mean(data[rectangle])) 168 pl3.set_edgecolor(color) 169 pl3.set_color(color) 170 ax.add_collection3d(pl3) 171 172 #deal with prism faces 173 triface=np.vstack((elements[:,0:3],elements[:,3:6])) 174 tmp = np.ascontiguousarray(triface).view(np.dtype((np.void, triface.dtype.itemsize * triface.shape[1]))) 175 _, idx = np.unique(tmp, return_index=True) 176 triel= triface[idx] 177 for triangle in triel: 178 tri=zip(x[triangle],y[triangle],z[triangle]) 179 pl3=Poly3DCollection([tri]) 180 color=loccmap.to_rgba(np.mean(data[triangle])) 181 pl3.set_edgecolor(color) 182 pl3.set_color(color) 183 ax.add_collection3d(pl3) 184 185 ax.set_xlim([min(x),max(x)]) 186 ax.set_ylim([min(y),max(y)]) 187 ax.set_zlim([min(z),max(z)]) 188 189 #raise ValueError('plot_unit error: 3D element plot not supported yet') 102 190 return 103 191 # }}} -
issm/trunk-jpl/src/m/plot/plotdoc.py
r21443 r21444 8 8 'mesh':' draw mesh using trisurf', 9 9 'BC':' this will draw all the boundary conditions (Dirichlet and Neumann).', 10 'elementnumbering':' numbering of elements (matlab indices)'} 10 'elementnumbering':' numbering of elements (matlab indices)', 11 '3D disclaimer':'3D is implemented with plot3d for now this is not optimal and may change to mayavi at some point. The impelementation is on the development side for now so expect some issue and question your plotting before you results.'} 11 12 TODOdata={'basal_drag':' plot the basal drag on the bed (in kPa) based on the velocity in md.initialization', 12 13 'basal_dragx or basal_dragy' :' plot a component of the basal drag on the bed (in kPa)', … … 18 19 'driving_stress':' plot the driving stress (in kPa)', 19 20 'elements_type':' model used for each element', 20 21 21 'highlightvertices':' to highlight vertices (use highlight option to enter the vertex list', 22 22 'referential':' stressbalance referential', … … 47 47 48 48 pyoptions={'axis':" show ('on') or hide ('off') axes", 49 49 'caxis':" modify colorbar range. (array of type [a b] where b>=a)", 50 50 'colorlevels':" N, number of levels to use", 51 51 'colorbar':" add colorbar (string 'on','off' or 'one')", 52 52 'axes_pad':" spacing between axes (default is 0.25)", 53 53 'colorbartitle':" colorbar title (string)", 54 55 54 'colorbarticks':" set colorbar ticks manually (list)", 55 'colorbarfontsize':" specify colorbar fontsize", 56 56 'colormap':" change the default colormap ('viridis' is the default)", 57 57 'contourlevels':" N or [value1,...] add the contours of the specified values or N contours", 58 58 'streamlines':" TOFIX argument does nothing", 59 59 'edgecolor':" color of mesh edges. RGB tuple or standard string", -
issm/trunk-jpl/src/m/plot/plotmodel.py
r21440 r21444 58 58 if options.list[0].exist('figsize'): 59 59 figsize=options.list[0].getfieldvalue('figsize') 60 fig=plt.figure(figurenumber,figsize=(figsize[0],figsize[1]) ,tight_layout=True)60 fig=plt.figure(figurenumber,figsize=(figsize[0],figsize[1]))#,tight_layout=True) 61 61 else: 62 fig=plt.figure(figurenumber ,tight_layout=True)62 fig=plt.figure(figurenumber)#,tight_layout=True) 63 63 fig.clf() 64 64
Note:
See TracChangeset
for help on using the changeset viewer.