Changeset 21283


Ignore:
Timestamp:
10/18/16 01:05:04 (8 years ago)
Author:
bdef
Message:

CHG: colormap treatment grid subplot tweak NEW: BC ability plotdoc

Location:
issm/trunk-jpl/src/m/plot
Files:
3 added
8 edited

Legend:

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

    r21276 r21283  
    165165                options.addfielddefault('clim',lims)
    166166        else:
    167                 if len(data)>0: lims=[data.min(),data.max()]
    168                 else: lims=[0,1]
     167                if len(data)>0:
     168                        lims=[data.min(),data.max()]
     169                else:
     170                        lims=[0,1]
    169171        # }}}
    170172        # {{{ shading TODO
     
    177179        # }}}
    178180        # {{{ colormap
    179         # default sequential colormap
    180         defaultmap=truncate_colormap(mpl.cm.gnuplot2,0.1,0.9,128)
    181         cmap=options.getfieldvalue('colormap',defaultmap)
    182         if options.exist('log'):
    183                 norm = mpl.colors.LogNorm(vmin=lims[0], vmax=lims[1])
    184         else:
    185                 norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
    186         options.addfield('colornorm',norm)
    187         if options.exist('cmap_set_bad'):
    188                 NaNcolor=options.getfieldvalue('cmap_set_bad','w')
    189                 cmap.set_bad(NaNcolor,1.0)
     181        if options.exist('colornorm'):
     182                norm=options.getfieldvalue('colornorm')
     183        if options.exist('colormap'):
     184                cmap=options.getfieldvalue('colormap')
    190185        cbar_extend=0
    191186        if options.exist('cmap_set_over'):
    192                 over=options.getfieldvalue('cmap_set_over','0.5')
    193                 cmap.set_over(over)
    194187                cbar_extend+=1
    195188        if options.exist('cmap_set_under'):
    196                 under=options.getfieldvalue('cmap_set_under','0.5')
    197                 cmap.set_under(under)
    198189                cbar_extend+=2
    199         options.addfield('colormap',cmap)
    200190        # }}}
    201191        # {{{ contours
     
    215205                elif cbar_extend==3:
    216206                        extend='both'
    217                 cb = mpl.colorbar.ColorbarBase(ax.cax, cmap=cmap, norm=norm, extend=extend)
     207                cb = mpl.colorbar.ColorbarBase(ax.cax,cmap=cmap, norm=norm, extend=extend)
    218208                if options.exist('alpha'):
    219209                        cb.set_alpha(options.getfieldvalue('alpha'))
     
    246236                plt.sca(ax) # return to original axes control
    247237        # }}}
    248         # {{{ expdisp
    249         if options.exist('expdisp'):
    250             expdisp(ax,options)
     238        # {{{ expdisp TOFIX
     239        # if options.exist('expdisp'):
     240        #       expdisp(ax,options)
    251241        # }}}
    252242        # {{{ area TODO
  • issm/trunk-jpl/src/m/plot/checkplotoptions.py

    r21253 r21283  
    151151        # {{{ scale ruler
    152152        if options.exist('scaleruler'):
    153                 if 'on' in options.exist('scaleruler','on'):
     153                if 'on' in options.getfieldvalue('scaleruler','off'):
    154154                        Lx=max(md.mesh.x)-min(md.mesh.x)
    155155                        Ly=max(md.mesh.y)-min(md.mesh.y)
    156                         options.changefieldvalue('scaleruler',[min(md.mesh.x)+6./8.*Lx, min(md.mesh.y)+1./10.*Ly, 10**(ceil(log10(Lx)))/5, floor(Lx/100), 5])
     156                        options.changefieldvalue('scaleruler',[min(md.mesh.x)+6./8.*Lx, min(md.mesh.y)+1./10.*Ly, 10**(np.ceil(np.log10(Lx)))/5, np.floor(Lx/100), 5])
    157157        # }}}
    158158        # {{{ log scale
  • issm/trunk-jpl/src/m/plot/plot_manager.py

    r21253 r21283  
    77from checkplotoptions import checkplotoptions
    88from plot_mesh import plot_mesh
     9from plot_BC import plot_BC
    910from processmesh import processmesh
    1011from processdata import processdata
     
    5758        # {{{ dealing with special plot (mesh for now)
    5859        if isinstance(data,(str,unicode)):
    59                 # convert string to lower case for a case-insensitive comparison
    60                 if data.lower()=='mesh':
    61                         plot_mesh(md,options,ax)
    62                         applyoptions(md,[],options,fig,ax)
    63                         fig.delaxes(fig.axes[1]) # hack to remove colorbar after the fact
     60                if data=='mesh':
     61                        plot_mesh(md,options,fig,ax)
     62                        #fig.delaxes(fig.axes[1]) # hack to remove colorbar after the fact
    6463                        return
    65                 elif data.lower()=='none':
     64                elif data=='BC':
     65                        plot_BC(md,options,fig,ax)
     66                        return
     67                elif data=='none':
    6668                        print 'no data provided to plot (TODO: write plot_none.py)'
    6769                        applyoptions(md,[],options,fig,ax)
  • issm/trunk-jpl/src/m/plot/plot_mesh.py

    r17955 r21283  
    77from applyoptions import applyoptions
    88
    9 def plot_mesh(md,options,ax):
     9def plot_mesh(md,options,fig,ax):
    1010        '''
    1111        PLOT_MESH - plot model mesh
     
    2828        options.addfielddefault('colorbar','off')
    2929        options.addfielddefault('ticklabels','on')
     30        applyoptions(md,[],options,fig,ax)
  • issm/trunk-jpl/src/m/plot/plot_quiver.py

    r21256 r21283  
    1414                color=datanorm
    1515        #scaling of arrow length (giving info to change as it seems that there is no better way to work arround it)
    16         scale=options.getfieldvalue('scale',scaler)
    17         print('the current value for scale is {}, increase it to shorten the arrows'.format(scale))
     16        scale=options.getfieldvalue('scaling',scaler)
     17        print('the current value for "scaling" is {}, increase it to shorten the arrows'.format(scale))
    1818        #sizing of the arrows
    1919        width=options.getfieldvalue('width',5.0e-3)
     
    3232                                                                angles='xy')
    3333        else:
     34                if options.exist('colornorm'):
     35                        norm=options.getfieldvalue('colornorm')
     36                if options.exist('colormap'):
     37                        cmap=options.getfieldvalue('colormap')         
    3438                Q=ax.quiver(x,y,vx,vy,color,cmap=cmap,norm=norm,
    3539                                                                scale=scale,scale_units='xy',
  • issm/trunk-jpl/src/m/plot/plot_unit.py

    r21256 r21283  
    2929        # {{{ define wich colormap to use
    3030        try:
    31                 defaultmap=plt.cm.viridis
     31                defaultmap=plt.cm.get_cmap('viridis',colorlevels)
    3232        except AttributeError:
    3333                print("Viridis can't be found (probably too old Matplotlib) reverting to gnuplot colormap")
    34                 defaultmap=truncate_colormap(mpl.cm.gnuplot2,0.1,0.9,128)
     34                defaultmap=truncate_colormap('gnuplot2',0.1,0.9,colorlevels)
    3535        cmap=options.getfieldvalue('colormap',defaultmap)
    3636        if options.exist('cmap_set_over'):
     
    4040                under=options.getfieldvalue('cmap_set_under','0.5')
    4141                cmap.set_under(under)
     42        options.addfield('colormap',cmap)
    4243        # }}}   
    4344        # {{{ Get the colormap limits
     
    5758        else:
    5859                norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
     60        if options.exist('log'):
     61                norm = mpl.colors.LogNorm(vmin=lims[0], vmax=lims[1])
     62        else:
     63                norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
     64        options.addfield('colornorm',norm)
    5965        # }}}
    6066       
     
    8187                                triangles=mpl.tri.Triangulation(x,y,elements)
    8288                        ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha)
    83 #                       ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,extend='both')
    8489                        if edgecolor != 'None':
    8590                                ax.triplot(x,y,elements,color=edgecolor)
  • issm/trunk-jpl/src/m/plot/plotmodel.py

    r21254 r21283  
    11import numpy as np
    22from plotoptions import plotoptions
     3from plotdoc import plotdoc
    34
    45try:
     
    1314
    1415def plotmodel(md,*args):
    15         '''     at command prompt, type 'plotdoc' for additional documentation
     16        '''     at command prompt, type 'plotdoc()' for additional documentation
    1617        '''
    1718
     
    2122        #get number of subplots
    2223        subplotwidth=ceil(sqrt(options.numberofplots))
    23        
    2424        #Get figure number and number of plots
    2525        figurenumber=options.figurenumber
     
    5252        #Go through plots
    5353        if numberofplots:
    54                
    5554                #if plt.fignum_exists(figurenumber):
    5655                #       plt.cla()
     
    6463                fig.clf()
    6564
     65                backgroundcolor=options.list[0].getfieldvalue('backgroundcolor',(0.7,0.7,0.7))
     66                fig.set_facecolor(backgroundcolor)
     67
     68
     69                translator={'on':'each',
     70                                                                'off':'None',
     71                                                                'one':'single'}
    6672                # options needed to define plot grid
     73                plotnum=options.numberofplots
    6774                direction=options.list[0].getfieldvalue('direction','row') # row,column
    6875                axes_pad=options.list[0].getfieldvalue('axes_pad',0.25)
    6976                add_all=options.list[0].getfieldvalue('add_all',True) # True,False
    7077                share_all=options.list[0].getfieldvalue('share_all',True) # True,False
    71                 label_mode=options.list[0].getfieldvalue('label_mode','1') # 1,L,all
    72                 cbar_mode=options.list[0].getfieldvalue('cbar_mode','each') # none,single,each
    73                 cbar_location=options.list[0].getfieldvalue('cbar_location','right') # right,top
    74                 cbar_size=options.list[0].getfieldvalue('cbar_size','5%')
    75                 cbar_pad=options.list[0].getfieldvalue('cbar_pad','2.5%') # None or %
     78                label_mode=options.list[0].getfieldvalue('label_mode','L') # 1,L,all
     79                colorbar=options.list[0].getfieldvalue('colorbar','on') # on, off (single)
     80                cbar_mode=translator[colorbar]
     81                cbar_location=options.list[0].getfieldvalue('colorbarpos','right') # right,top
     82                cbar_size=options.list[0].getfieldvalue('colorbarsize','5%')
     83                cbar_pad=options.list[0].getfieldvalue('colorbarpad','2.5%') # None or %
    7684               
    7785                axgrid=ImageGrid(fig, 111,
    7886                                nrows_ncols=(nrows,ncols),
     87                                ngrids=plotnum,
    7988                                direction=direction,
    8089                                axes_pad=axes_pad,
     
    8897                                )
    8998
    90                 if cbar_mode=='none':
    91                         for ax in axgrid.cbar_axes: fig._axstack.remove(ax)
     99                if cbar_mode=='off':
     100                        for ax in axgrid.cbar_axes:
     101                                fig._axstack.remove(ax)
    92102
    93103                for i in xrange(numberofplots):
  • issm/trunk-jpl/src/m/plot/processdata.py

    r21253 r21283  
    1 from math import isnan
    21import numpy as np
    32
     
    1817        # {{{ Initialisation and grabbing auxiliaries
    1918        # check format
    20         if (len(data)==0 or (len(data)==1 and not isinstance(data,dict) and isnan(data).all())):
     19        if (len(data)==0 or (len(data)==1 and not isinstance(data,dict) and np.isnan(data).all())):
    2120                raise ValueError("processdata error message: 'data' provided is empty")
     21        # get the shape
    2222        if 'numberofvertices2d' in dir(md.mesh):
    2323                numberofvertices2d=md.mesh.numberofvertices2d
     
    2929        #initialize datatype
    3030        datatype=0
    31         # init patches
    3231        # get datasize
    3332        if np.ndim(procdata)==1:
    34                 datasize=np.array([len(procdata),1])
     33                datasize=(np.shape(procdata)[0],1)
     34        elif np.ndim(procdata)==2:
     35                datasize=np.shape(procdata)
     36        elif np.ndim(procdata)==3:
     37                if np.shape(procdata)[0]==2:
     38                        #treating a dim two list that needs to be stacked
     39                        procdata=np.hstack((procdata[0,:,:],procdata[1,:,:]))
     40                        datasize=np.shape(procdata)
     41                else:
     42                        raise ValueError('data list contains more than two vectore, we can not cope with that')
    3543        else:
    36                 datasize=np.shape(procdata)
    37                 if len(datasize)>2:
    38                         raise ValueError('data passed to plotmodel has more than 2 dimensions; check that column vectors are rank-1')
     44                raise ValueError('data passed to plotmodel has bad dimensions; check that column vectors are rank-1')
    3945  # }}}     
    4046        # {{{ process NaN's if any
     
    6672        # }}} 
    6773        # {{{ element data
     74
    6875        if datasize[0]==md.mesh.numberofelements and datasize[1]==1:
    69                 print'ploting elements'
    7076                #initialize datatype if non patch
    7177                if datatype!=4 and datatype!=5:
     
    8591                                print('plotmodel warning: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements')
    8692                # }}} 
     93
    8794        # }}} 
    8895        # {{{ node data
    8996        if datasize[0]==md.mesh.numberofvertices and datasize[1]==1:
    90                 print'ploting nodes'
    9197                datatype=2
    9298                # {{{ Mask
Note: See TracChangeset for help on using the changeset viewer.