Changeset 17640
- Timestamp:
- 04/03/14 17:22:08 (11 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/applyoptions.py
r17635 r17640 157 157 elif options.exist('caxis'): 158 158 lims=options.getfieldvalue('caxis') 159 if len(lims)!=2: 160 print 'WARNING: clim/caxis should be passed as a list of length 2' 161 else: 162 p.clim(lims[0],lims[1]) 159 options.addfielddefault('clim',lims) 160 else: 161 lims=[min(data.flatten()),max(data.flatten())] 162 if len(lims)!=2: 163 print 'WARNING: clim/caxis should be passed as a list of length 2' 163 164 #}}} 164 165 … … 179 180 #colorbar {{{ 180 181 if options.getfieldvalue('colorbar',1)==1: 181 if options.exist('clim'): 182 # build custom colorbar (does not yet allow customizing the location) 183 fig = p.gcf() 184 ax = p.gca() 185 divider = make_axes_locatable(ax) 186 cax = divider.new_horizontal("5%", pad=0.05, axes_class=mpl.axes.Axes) 187 fig.add_axes(cax) 188 norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1]) 189 cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm) 190 else: 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) 182 fig = p.gcf() 183 ax = p.gca() 184 divider = make_axes_locatable(ax) 185 cax = divider.new_horizontal("5%", pad=0.05, axes_class=mpl.axes.Axes) 186 fig.add_axes(cax) 187 norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1]) 188 cbar_extend=0 189 if options.exist('cmap_set_over'): 190 over=options.getfieldvalue('cmap_set_over','0.5') 191 cmap.set_over(over) 192 cbar_extend+=1 193 if options.exist('cmap_set_under'): 194 under=options.getfieldvalue('cmap_set_under','0.5') 195 cmap.set_under(under) 196 cbar_extend+=2 197 if cbar_extend==0: 198 extend='neither' 199 elif cbar_extend==1: 200 extend='max' 201 elif cbar_extend==2: 202 extend='min' 203 elif cbar_extend==3: 204 extend='both' 205 cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm, extend=extend) 199 206 cb.locator=MaxNLocator(nbins=5) # default 5 ticks 200 207 cb.update_ticks() -
issm/trunk-jpl/src/m/plot/plot_unit.py
r17635 r17640 7 7 8 8 def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options): 9 """ 10 PLOT_UNIT - unit plot, display data 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 """ 11 17 12 Usage: 13 plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options) 18 #edgecolor 19 edgecolor=options.getfieldvalue('edgecolor','None') 20 21 #number of colorlevels for plots 22 colorlevels=options.getfieldvalue('colorlevels',256) 23 24 #colormap 25 cmap=options.getfieldvalue('colormap',mpl.cm.gnuplot2) 26 cbar_extend=0 27 if options.exist('cmap_set_over'): 28 over=options.getfieldvalue('cmap_set_over','0.5') 29 cmap.set_over(over) 30 cbar_extend+=1 31 if options.exist('cmap_set_under'): 32 under=options.getfieldvalue('cmap_set_under','0.5') 33 cmap.set_under(under) 34 cbar_extend+=1 14 35 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 #colormap 25 cmap=options.getfieldvalue('colormap',mpl.cm.gnuplot2) 26 27 if datatype==1: 28 #element plot 29 if is2d: 30 p.tripcolor(x,y,elements,data,colorlevels,edgecolors=edgecolor) 31 else: 32 raise ValueError('plot_unit error: 3D element plot not supported yet') 33 return 34 35 elif datatype==2: 36 #node plot 37 if is2d: 38 p.tricontourf(x,y,elements,data,colorlevels,cmap=cmap) 39 if edgecolor != 'None': 40 p.triplot(x,y,elements,color=edgecolor) 41 else: 42 raise ValueError('plot_unit error: 3D node plot not supported yet') 43 return 44 45 elif datatype==3: 46 print 'plot_unit message: quiver plot not implemented yet' 47 return 48 49 elif datatype==4: 50 #P1 patch plot 51 print 'plot_unit message: P1 patch plot not implemented yet' 52 return 53 54 elif datatype==5: 55 print 'plot_unit message: P0 patch plot not implemented yet' 56 return 57 58 else: 36 #normalize colormap if clim/caxis specified 37 if options.exist('clim'): 38 lims=options.getfieldvalue('clim',[min(data),max(data)]) 39 elif options.exist('caxis'): 40 lims=options.getfieldvalue('caxis',[min(data),max(data)]) 41 else: 42 lims=[min(data),max(data)] 43 norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1]) 44 if datatype==1: 45 #element plot 46 if is2d: 47 p.tripcolor(x,y,elements,data,colorlevels,edgecolors=edgecolor) 48 else: 49 raise ValueError('plot_unit error: 3D element plot not supported yet') 50 return 51 52 elif datatype==2: 53 #node plot 54 if is2d: 55 p.tricontourf(x,y,elements,data,colorlevels,cmap=cmap,norm=norm) 56 if edgecolor != 'None': 57 p.triplot(x,y,elements,color=edgecolor) 58 else: 59 raise ValueError('plot_unit error: 3D node plot not supported yet') 60 return 61 62 elif datatype==3: 63 print 'plot_unit message: quiver plot not implemented yet' 64 return 65 66 elif datatype==4: 67 #P1 patch plot 68 print 'plot_unit message: P1 patch plot not implemented yet' 69 return 70 71 elif datatype==5: 72 print 'plot_unit message: P0 patch plot not implemented yet' 73 return 74 75 else: 59 76 raise ValueError('datatype=%d not supported' % datatype)
Note:
See TracChangeset
for help on using the changeset viewer.