Changeset 21440


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

NEW: adding 3D treatment for mesh and clean way to remove the colorbar

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  
    2424        from plot_overlay import plot_overlay
    2525
    26 def plot_manager(md,options,fig,ax):
     26def plot_manager(md,options,fig,axgrid,gridindex):
    2727        '''
    2828        PLOT_MANAGER - distribute the plots called by plotmodel
     
    4646        options.addfielddefault('ticklabels','on')
    4747
     48        ax=axgrid[gridindex]
    4849        # {{{ basemap plot TOFIX
    4950        #if options.exist('basemap'):
     
    6061        if isinstance(data,(str,unicode)):
    6162                if data=='mesh':
    62                         plot_mesh(md,options,fig,ax)
     63                        plot_mesh(md,options,fig,axgrid,gridindex)
     64
    6365                        #fig.delaxes(fig.axes[1]) # hack to remove colorbar after the fact
    6466                        return
  • issm/trunk-jpl/src/m/plot/plot_mesh.py

    r21283 r21440  
    33except ImportError:
    44        print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
    5 
     5import numpy as np
     6import matplotlib as mpl
    67from processmesh import processmesh
    78from applyoptions import applyoptions
    8 
    9 def plot_mesh(md,options,fig,ax):
     9from matplotlib.patches import Polygon
     10from mpl_toolkits.mplot3d.art3d import Line3DCollection
     11def plot_mesh(md,options,fig,axgrid,gridindex):
    1012        '''
    1113        PLOT_MESH - plot model mesh
     
    1618                See also: PLOTMODEL
    1719        '''
     20        x,y,z,elements,is2d,isplanet=processmesh(md,'mesh',options)
    1821
    19         x,y,z,elements,is2d,isplanet=processmesh(md,[],options)
    20 
     22        ax=axgrid[gridindex]
     23        fig.delaxes(axgrid.cbar_axes[gridindex])
     24       
    2125        if is2d:
    2226                ax.triplot(x,y,elements)
    2327        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)])
    2656        #apply options
    2757        options.addfielddefault('title','Mesh')
  • issm/trunk-jpl/src/m/plot/plotmodel.py

    r21426 r21440  
    22from plotoptions import plotoptions
    33from plotdoc import plotdoc
     4from plot_manager import plot_manager
     5from math import ceil, sqrt
    46
    57try:
    68        import pylab as p
    79        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
    912except ImportError:
    1013        print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
    11 
    12 from plot_manager import plot_manager
    13 from math import ceil, sqrt
    1414
    1515def plotmodel(md,*args):
     
    8383                cbar_pad=options.list[0].getfieldvalue('colorbarpad','2.5%') # None or %
    8484
    85                 axgrid=ImageGrid(fig, 111,
     85                axgrid=ImageGrid(fig,111,
    8686                                nrows_ncols=(nrows,ncols),
    8787                                ngrids=plotnum,
     
    9494                                cbar_location=cbar_location,
    9595                                cbar_size=cbar_size,
    96                                 cbar_pad=cbar_pad
    97                                 )
     96                                cbar_pad=cbar_pad)
    9897
    9998                if cbar_mode=='None':
     
    101100                                fig._axstack.remove(ax)
    102101
    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)
    106104                fig.show()
    107105        else:
  • issm/trunk-jpl/src/m/plot/processmesh.py

    r21427 r21440  
    1515        if md.mesh.numberofvertices==0:
    1616                raise ValueError('processmesh error: mesh is empty')
    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')
     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')
    1919        # }}}
    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
    3845               
    39                 try:
    40                         elements=md.mesh.elements2d-1
    41                 except AttributeError:
    42                         elements=md.mesh.elements-1
    43 
    44                 #is it a 2D plot?
    45                 if md.mesh.dimension()==2 or options.getfieldvalue('layer',0)>=1:
    46                         is2d=1
    47                 else:
    48                         is2d=0
    49 
    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 extruded
    55                          z=np.zeros(np.size(x))
    56                          elements=elements
    57         else:
    58                 #Process mesh for plotting
    59                 if md.mesh.dimension()==2:
    60                         is2d=1
    61                 else:
    62                         # process polycollection here for 3D plot
    63                         is2d=0
    6446        #units
    6547        if options.exist('unit'):
Note: See TracChangeset for help on using the changeset viewer.