Changeset 21283
- Timestamp:
- 10/18/16 01:05:04 (8 years ago)
- 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 165 165 options.addfielddefault('clim',lims) 166 166 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] 169 171 # }}} 170 172 # {{{ shading TODO … … 177 179 # }}} 178 180 # {{{ 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') 190 185 cbar_extend=0 191 186 if options.exist('cmap_set_over'): 192 over=options.getfieldvalue('cmap_set_over','0.5')193 cmap.set_over(over)194 187 cbar_extend+=1 195 188 if options.exist('cmap_set_under'): 196 under=options.getfieldvalue('cmap_set_under','0.5')197 cmap.set_under(under)198 189 cbar_extend+=2 199 options.addfield('colormap',cmap)200 190 # }}} 201 191 # {{{ contours … … 215 205 elif cbar_extend==3: 216 206 extend='both' 217 cb = mpl.colorbar.ColorbarBase(ax.cax, 207 cb = mpl.colorbar.ColorbarBase(ax.cax,cmap=cmap, norm=norm, extend=extend) 218 208 if options.exist('alpha'): 219 209 cb.set_alpha(options.getfieldvalue('alpha')) … … 246 236 plt.sca(ax) # return to original axes control 247 237 # }}} 248 # {{{ expdisp 249 if options.exist('expdisp'):250 238 # {{{ expdisp TOFIX 239 # if options.exist('expdisp'): 240 # expdisp(ax,options) 251 241 # }}} 252 242 # {{{ area TODO -
issm/trunk-jpl/src/m/plot/checkplotoptions.py
r21253 r21283 151 151 # {{{ scale ruler 152 152 if options.exist('scaleruler'): 153 if 'on' in options. exist('scaleruler','on'):153 if 'on' in options.getfieldvalue('scaleruler','off'): 154 154 Lx=max(md.mesh.x)-min(md.mesh.x) 155 155 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]) 157 157 # }}} 158 158 # {{{ log scale -
issm/trunk-jpl/src/m/plot/plot_manager.py
r21253 r21283 7 7 from checkplotoptions import checkplotoptions 8 8 from plot_mesh import plot_mesh 9 from plot_BC import plot_BC 9 10 from processmesh import processmesh 10 11 from processdata import processdata … … 57 58 # {{{ dealing with special plot (mesh for now) 58 59 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 64 63 return 65 elif data.lower()=='none': 64 elif data=='BC': 65 plot_BC(md,options,fig,ax) 66 return 67 elif data=='none': 66 68 print 'no data provided to plot (TODO: write plot_none.py)' 67 69 applyoptions(md,[],options,fig,ax) -
issm/trunk-jpl/src/m/plot/plot_mesh.py
r17955 r21283 7 7 from applyoptions import applyoptions 8 8 9 def plot_mesh(md,options, ax):9 def plot_mesh(md,options,fig,ax): 10 10 ''' 11 11 PLOT_MESH - plot model mesh … … 28 28 options.addfielddefault('colorbar','off') 29 29 options.addfielddefault('ticklabels','on') 30 applyoptions(md,[],options,fig,ax) -
issm/trunk-jpl/src/m/plot/plot_quiver.py
r21256 r21283 14 14 color=datanorm 15 15 #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('scal e',scaler)17 print('the current value for scaleis {}, 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)) 18 18 #sizing of the arrows 19 19 width=options.getfieldvalue('width',5.0e-3) … … 32 32 angles='xy') 33 33 else: 34 if options.exist('colornorm'): 35 norm=options.getfieldvalue('colornorm') 36 if options.exist('colormap'): 37 cmap=options.getfieldvalue('colormap') 34 38 Q=ax.quiver(x,y,vx,vy,color,cmap=cmap,norm=norm, 35 39 scale=scale,scale_units='xy', -
issm/trunk-jpl/src/m/plot/plot_unit.py
r21256 r21283 29 29 # {{{ define wich colormap to use 30 30 try: 31 defaultmap=plt.cm. viridis31 defaultmap=plt.cm.get_cmap('viridis',colorlevels) 32 32 except AttributeError: 33 33 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) 35 35 cmap=options.getfieldvalue('colormap',defaultmap) 36 36 if options.exist('cmap_set_over'): … … 40 40 under=options.getfieldvalue('cmap_set_under','0.5') 41 41 cmap.set_under(under) 42 options.addfield('colormap',cmap) 42 43 # }}} 43 44 # {{{ Get the colormap limits … … 57 58 else: 58 59 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) 59 65 # }}} 60 66 … … 81 87 triangles=mpl.tri.Triangulation(x,y,elements) 82 88 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')84 89 if edgecolor != 'None': 85 90 ax.triplot(x,y,elements,color=edgecolor) -
issm/trunk-jpl/src/m/plot/plotmodel.py
r21254 r21283 1 1 import numpy as np 2 2 from plotoptions import plotoptions 3 from plotdoc import plotdoc 3 4 4 5 try: … … 13 14 14 15 def plotmodel(md,*args): 15 ''' at command prompt, type 'plotdoc ' for additional documentation16 ''' at command prompt, type 'plotdoc()' for additional documentation 16 17 ''' 17 18 … … 21 22 #get number of subplots 22 23 subplotwidth=ceil(sqrt(options.numberofplots)) 23 24 24 #Get figure number and number of plots 25 25 figurenumber=options.figurenumber … … 52 52 #Go through plots 53 53 if numberofplots: 54 55 54 #if plt.fignum_exists(figurenumber): 56 55 # plt.cla() … … 64 63 fig.clf() 65 64 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'} 66 72 # options needed to define plot grid 73 plotnum=options.numberofplots 67 74 direction=options.list[0].getfieldvalue('direction','row') # row,column 68 75 axes_pad=options.list[0].getfieldvalue('axes_pad',0.25) 69 76 add_all=options.list[0].getfieldvalue('add_all',True) # True,False 70 77 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 % 76 84 77 85 axgrid=ImageGrid(fig, 111, 78 86 nrows_ncols=(nrows,ncols), 87 ngrids=plotnum, 79 88 direction=direction, 80 89 axes_pad=axes_pad, … … 88 97 ) 89 98 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) 92 102 93 103 for i in xrange(numberofplots): -
issm/trunk-jpl/src/m/plot/processdata.py
r21253 r21283 1 from math import isnan2 1 import numpy as np 3 2 … … 18 17 # {{{ Initialisation and grabbing auxiliaries 19 18 # 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())): 21 20 raise ValueError("processdata error message: 'data' provided is empty") 21 # get the shape 22 22 if 'numberofvertices2d' in dir(md.mesh): 23 23 numberofvertices2d=md.mesh.numberofvertices2d … … 29 29 #initialize datatype 30 30 datatype=0 31 # init patches32 31 # get datasize 33 32 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') 35 43 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') 39 45 # }}} 40 46 # {{{ process NaN's if any … … 66 72 # }}} 67 73 # {{{ element data 74 68 75 if datasize[0]==md.mesh.numberofelements and datasize[1]==1: 69 print'ploting elements'70 76 #initialize datatype if non patch 71 77 if datatype!=4 and datatype!=5: … … 85 91 print('plotmodel warning: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements') 86 92 # }}} 93 87 94 # }}} 88 95 # {{{ node data 89 96 if datasize[0]==md.mesh.numberofvertices and datasize[1]==1: 90 print'ploting nodes'91 97 datatype=2 92 98 # {{{ Mask
Note:
See TracChangeset
for help on using the changeset viewer.