Changeset 21444


Ignore:
Timestamp:
12/15/16 03:14:02 (8 years ago)
Author:
bdef
Message:

NEW: adding 3D ability for standard data plot (may need to shift to mayavi on a later stage)

Location:
issm/trunk-jpl/src/m/plot
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/applyoptions.py

    r21435 r21444  
    1010        from mpl_toolkits.mplot3d import Axes3D
    1111        import matplotlib as mpl
    12         import pylab as p
    1312        import matplotlib.pyplot as plt
    1413except ImportError:
    1514        print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
    1615
    17 def applyoptions(md,data,options,fig,ax):
     16def applyoptions(md,data,options,fig,axgrid,gridindex):
    1817        '''
    1918        APPLYOPTIONS - apply options to current plot
     
    3029        # get handle to current figure and axes instance
    3130        #fig = p.gcf()
    32         #ax=p.gca()
     31        ax=     axgrid[gridindex]
    3332
    3433        # {{{ font
  • issm/trunk-jpl/src/m/plot/plot_manager.py

    r21442 r21444  
    9393        data2,datatype=processdata(md,data,options)
    9494        #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)
    9696        #apply all options
    97         applyoptions(md,data2,options,fig,ax)
     97        applyoptions(md,data2,options,fig,axgrid,gridindex)
    9898       
    9999        #ground overlay on kml plot_unit
  • issm/trunk-jpl/src/m/plot/plot_mesh.py

    r21440 r21444  
    99from matplotlib.patches import Polygon
    1010from mpl_toolkits.mplot3d.art3d import Line3DCollection
     11from mpl_toolkits.axes_grid1 import inset_locator
     12from mpl_toolkits.mplot3d import Axes3D
    1113def plot_mesh(md,options,fig,axgrid,gridindex):
    1214        '''
     
    2527        if is2d:
    2628                ax.triplot(x,y,elements)
     29
    2730        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               
    3237                AB=elements[:,0:2]
    3338                BC=elements[:,1:3]
     
    3944                BE=np.vstack((elements[:,1],elements[:,4])).T
    4045                CF=np.vstack((elements[:,2],elements[:,5])).T
    41 
     46               
    4247                tmpa=np.vstack((AB,BC,CA,DE,EF,FD,AD,BE,CF))
    4348                #deleting segments that appear multiple times
     
    5055                        pl3=Line3DCollection([tri],edgecolor='r')
    5156                        ax.add_collection3d(pl3)
    52 
     57                       
    5358                ax.set_xlim([min(x),max(x)])
    5459                ax.set_ylim([min(y),max(y)])
     
    5863        options.addfielddefault('colorbar','off')
    5964        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  
    11from cmaptools import truncate_colormap
    22from plot_quiver import plot_quiver
     3import numpy as  np
    34try:
    4         import pylab as p
    55        import matplotlib as mpl
    66        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
    810except ImportError:
    911        print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
    1012       
    11 def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,ax):
     13def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,fig,axgrid,gridindex):
    1214        """
    1315        PLOT_UNIT - unit plot, display data
     
    1820        See also: PLOTMODEL, PLOT_MANAGER
    1921        """
    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
    2128        #edgecolor
    2229        edgecolor=options.getfieldvalue('edgecolor','None')
     
    4249        options.addfield('colormap',cmap)
    4350        # }}}   
    44         # {{{ if plotting only one of several layers reduce dataset
     51        # {{{ if plotting only one of several layers reduce dataset, same for surface
    4552        if options.getfieldvalue('layer',0)>=1:
    46                 plotlayer=options.getfieldvalue('layer',1)
     53                plotlayer=options.getfieldvalue('layer',0)
    4754                if datatype==1:
    4855                        slicesize=np.shape(elements)[0]
     
    8491                        tri=ax.tripcolor(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,edgecolors=edgecolor)
    8592                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')
    87138                return
    88139        # }}}
     
    99150                                ax.triplot(x,y,elements,color=edgecolor)
    100151                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')
    102190                return
    103191        # }}}
  • issm/trunk-jpl/src/m/plot/plotdoc.py

    r21443 r21444  
    88                                        'mesh':' draw mesh using trisurf',
    99                                        '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.'}
    1112        TODOdata={'basal_drag':' plot the basal drag on the bed (in kPa) based on the velocity in md.initialization',
    1213                                                'basal_dragx or basal_dragy' :' plot a component of the basal drag on the bed (in kPa)',
     
    1819                                                'driving_stress':' plot the driving stress (in kPa)',
    1920                                                'elements_type':' model used for each element',
    20                                                
    2121                                                'highlightvertices':' to highlight vertices (use highlight option to enter the vertex list',
    2222                                                'referential':' stressbalance referential',
     
    4747       
    4848        pyoptions={'axis':" show ('on') or hide ('off') axes",
    49                                                 'caxis':" modify  colorbar range. (array of type [a b] where b>=a)",
     49                                                'caxis':" modify  colorbar range. (array of type [a b] where b>=a)",
    5050                                                 'colorlevels':" N, number of levels to use",
    5151                                                 'colorbar':" add colorbar (string 'on','off' or 'one')",
    5252                                                 'axes_pad':" spacing between axes (default is 0.25)",
    5353                                                 'colorbartitle':" colorbar title (string)",
    54                                                 'colorbarticks':" set colorbar ticks manually (list)",
    55                                                 'colorbarfontsize':" specify colorbar fontsize",
     54                                                'colorbarticks':" set colorbar ticks manually (list)",
     55                                                'colorbarfontsize':" specify colorbar fontsize",
    5656                                                 'colormap':" change the default colormap ('viridis' is the default)",
    57                                                 'contourlevels':" N or [value1,...] add the contours of the specified values or N contours",
     57                                                'contourlevels':" N or [value1,...] add the contours of the specified values or N contours",
    5858                                                 'streamlines':" TOFIX argument does nothing",
    5959                                                 'edgecolor':" color of mesh edges. RGB tuple or standard string",
  • issm/trunk-jpl/src/m/plot/plotmodel.py

    r21440 r21444  
    5858                if options.list[0].exist('figsize'):
    5959                        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)
    6161                else:
    62                         fig=plt.figure(figurenumber,tight_layout=True)
     62                        fig=plt.figure(figurenumber)#,tight_layout=True)
    6363                fig.clf()
    6464
Note: See TracChangeset for help on using the changeset viewer.