Changeset 17698


Ignore:
Timestamp:
04/09/14 17:14:47 (11 years ago)
Author:
cborstad
Message:

CHG: misc changes for dealing with nan's when plotting in python

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

Legend:

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

    r17640 r17698  
    11import numpy as npy
     2from cmaptools import truncate_colormap
    23
    34try:
     
    173174
    174175        #colormap {{{
    175         cmap=options.getfieldvalue('colormap',mpl.cm.gnuplot2)
     176        # default sequential colormap
     177        defaultmap=truncate_colormap(mpl.cm.gnuplot2,0.1,0.9,128)
     178        cmap=options.getfieldvalue('colormap',defaultmap)
    176179        #}}}
    177180
  • issm/trunk-jpl/src/m/plot/plot_unit.py

    r17691 r17698  
    1 
     1from cmaptools import truncate_colormap
    22try:
    33        import pylab as p
     
    77
    88def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options):
    9    """
    10    PLOT_UNIT - unit plot, display data
    11    
    12         Usage:
    13                 plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options)
    14    
    15         See also: PLOTMODEL, PLOT_MANAGER
    16    """
    17 
    18    #edgecolor
    19    edgecolor=options.getfieldvalue('edgecolor','None')
    20    
    21    #number of colorlevels for plots
    22    colorlevels=options.getfieldvalue('colorlevels',256)
    23 
    24    alpha=options.getfieldvalue('alpha',1)
    25 
    26    #colormap
    27    cmap=options.getfieldvalue('colormap',mpl.cm.gnuplot2)
    28    if options.exist('cmap_set_over'):
    29       over=options.getfieldvalue('cmap_set_over','0.5')
    30       cmap.set_over(over)
    31    if options.exist('cmap_set_under'):
    32       under=options.getfieldvalue('cmap_set_under','0.5')
    33       cmap.set_under(under)
    34 
    35    #normalize colormap if clim/caxis specified
    36    if options.exist('clim'):
    37       lims=options.getfieldvalue('clim',[min(data),max(data)])
    38    elif options.exist('caxis'):
    39       lims=options.getfieldvalue('caxis',[min(data),max(data)])
    40    else:
    41       lims=[min(data),max(data)]
    42    norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
    43    if datatype==1:
    44       #element plot
    45         if is2d:
    46                 p.tripcolor(x,y,elements,data,colorlevels,cmap=cmap,edgecolors=edgecolor)
    47         else:
    48                 raise ValueError('plot_unit error: 3D element plot not supported yet')
    49         return
    50    
    51    elif datatype==2:
    52         #node plot
    53         if is2d:
    54                 p.tricontourf(x,y,elements,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha)
    55                 if edgecolor != 'None':
    56                         p.triplot(x,y,elements,color=edgecolor)
    57         else:
    58                 raise ValueError('plot_unit error: 3D node plot not supported yet')
    59         return
    60    
    61    elif datatype==3:
    62         print 'plot_unit message: quiver plot not implemented yet'
    63         return
    64    
    65    elif datatype==4:
    66         #P1 patch plot
    67         print 'plot_unit message: P1 patch plot not implemented yet'
    68         return
    69    
    70    elif datatype==5:
    71         print 'plot_unit message: P0 patch plot not implemented yet'
    72         return
    73    
    74    else:
     9        """
     10        PLOT_UNIT - unit plot, display data
     11       
     12                Usage:
     13                        plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options)
     14       
     15                See also: PLOTMODEL, PLOT_MANAGER
     16        """
     17       
     18        #edgecolor
     19        edgecolor=options.getfieldvalue('edgecolor','None')
     20       
     21        #number of colorlevels for plots
     22        colorlevels=options.getfieldvalue('colorlevels',256)
     23       
     24        alpha=options.getfieldvalue('alpha',1)
     25       
     26        #colormap
     27        # default sequential colormap
     28        defaultmap=truncate_colormap(mpl.cm.gnuplot2,0.1,0.9,128)
     29        cmap=options.getfieldvalue('colormap',defaultmap)
     30        if options.exist('cmap_set_over'):
     31           over=options.getfieldvalue('cmap_set_over','0.5')
     32           cmap.set_over(over)
     33        if options.exist('cmap_set_under'):
     34           under=options.getfieldvalue('cmap_set_under','0.5')
     35           cmap.set_under(under)
     36       
     37        #normalize colormap if clim/caxis specified
     38        if options.exist('clim'):
     39           lims=options.getfieldvalue('clim',[min(data),max(data)])
     40        elif options.exist('caxis'):
     41           lims=options.getfieldvalue('caxis',[min(data),max(data)])
     42        else:
     43           lims=[min(data),max(data)]
     44        norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
     45        if datatype==1:
     46           #element plot
     47                if is2d:
     48                        p.tripcolor(x,y,elements,data,colorlevels,cmap=cmap,edgecolors=edgecolor)
     49                else:
     50                        raise ValueError('plot_unit error: 3D element plot not supported yet')
     51                return
     52       
     53        elif datatype==2:
     54                #node plot
     55                if is2d:
     56                        p.tricontourf(x,y,elements,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha)
     57                        if edgecolor != 'None':
     58                                p.triplot(x,y,elements,color=edgecolor)
     59                else:
     60                        raise ValueError('plot_unit error: 3D node plot not supported yet')
     61                return
     62       
     63        elif datatype==3:
     64                print 'plot_unit message: quiver plot not implemented yet'
     65                return
     66       
     67        elif datatype==4:
     68                #P1 patch plot
     69                print 'plot_unit message: P1 patch plot not implemented yet'
     70                return
     71       
     72        elif datatype==5:
     73                print 'plot_unit message: P0 patch plot not implemented yet'
     74                return
     75       
     76        else:
    7577                raise ValueError('datatype=%d not supported' % datatype)
  • issm/trunk-jpl/src/m/plot/plotmodel.py

    r17617 r17698  
    5555                #handling the 'visible' option will need some check on whether ipython is currently in interactive or non-interactive mode
    5656
    57                 if not hold:
     57                if not hold: # TODO need to also check whether figurenumber is a new plot so that old plots are not mistakenly cleared
    5858                        p.clf()
    5959
  • issm/trunk-jpl/src/m/plot/processdata.py

    r17696 r17698  
    4646        if npy.any(npy.isnan(procdata)):
    4747                procdata[npy.isnan(procdata)]=nanfill
     48                options.addfielddefault('cmap_set_under','1')
     49                options.addfielddefault('clim',[min(data),max(data)])
    4850                print "WARNING: nan's treated as -9999 by default.  Change using pairoption 'nan',nan_fill_value in plotmodel call"
    4951
Note: See TracChangeset for help on using the changeset viewer.