Changeset 17635


Ignore:
Timestamp:
04/03/14 14:57:10 (11 years ago)
Author:
cborstad
Message:

CHG: better default handling of colormap in python plots

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

Legend:

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

    r17256 r17635  
     1import numpy as npy
     2
    13try:
    24        from matplotlib.ticker import MaxNLocator
     
    153155        if options.exist('clim'):
    154156                lims=options.getfieldvalue('clim')
     157        elif options.exist('caxis'):
     158                lims=options.getfieldvalue('caxis')
    155159                if len(lims)!=2:
    156                         print 'WARNING: clim should be passed as a list of length 2'
     160                        print 'WARNING: clim/caxis should be passed as a list of length 2'
    157161                else:
    158162                        p.clim(lims[0],lims[1])
     
    167171        #}}}
    168172
    169         #colormap
     173        #colormap {{{
     174        cmap=options.getfieldvalue('colormap',mpl.cm.gnuplot2)
     175        #}}}
    170176
    171177        #wrapping
     
    180186                        cax = divider.new_horizontal("5%", pad=0.05, axes_class=mpl.axes.Axes)
    181187                        fig.add_axes(cax)
    182                         cmap = mpl.cm.jet
    183188                        norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
    184189                        cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm)
    185190                else:
    186                         cb=p.colorbar()
     191                        # build custom colorbar (does not yet allow customizing the location)
     192                        fig = p.gcf()
     193                        ax = p.gca()
     194                        divider = make_axes_locatable(ax)
     195                        cax = divider.new_horizontal("5%", pad=0.05, axes_class=mpl.axes.Axes)
     196                        fig.add_axes(cax)
     197                        norm = mpl.colors.Normalize(vmin=npy.min(data.flatten()), vmax=npy.max(data.flatten()))
     198                        cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm)
    187199                cb.locator=MaxNLocator(nbins=5) # default 5 ticks
    188200                cb.update_ticks()
  • issm/trunk-jpl/src/m/plot/plot_unit.py

    r17203 r17635  
    22try:
    33        import pylab as p
     4        import matplotlib as mpl
    45except ImportError:
    56        print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
     
    2122        colorlevels=options.getfieldvalue('colorlevels',256)
    2223
     24        #colormap
     25        cmap=options.getfieldvalue('colormap',mpl.cm.gnuplot2)
     26
    2327        if datatype==1:
    2428                #element plot
     
    3236                #node plot
    3337                if is2d:
    34                         p.tricontourf(x,y,elements,data,colorlevels)
     38                        p.tricontourf(x,y,elements,data,colorlevels,cmap=cmap)
    3539                        if edgecolor != 'None':
    3640                                p.triplot(x,y,elements,color=edgecolor)
Note: See TracChangeset for help on using the changeset viewer.