def plot(self,data=None,mesh=None,template=None,meshfill=None,x=None,bg=0,multiple=1.1): # Create the vcs canvas if x is None: x=vcs.init() ## Continents bug x.setcontinentstype(0) # gets the thing to plot ! if data is None: data=self.get() # Do we use a predefined template ? if template is None: template=x.createtemplate() # Now sets all the things for the template... # Sets a bunch of template attributes to off for att in [ 'line1','line2','line3','line4', 'box2','box3','box4', 'min','max','mean', 'xtic1','xtic2', 'ytic1','ytic2', 'xvalue','yvalue','zvalue','tvalue', 'xunits','yunits','zunits','tunits', 'source','title','dataname', ]: a=getattr(template,att) setattr(a,'priority',0) for att in [ 'xname','yname', ]: a=getattr(template,att) setattr(a,'priority',0) template.data.x1=self.PLOT_SETTINGS.x1 template.data.x2=self.PLOT_SETTINGS.x2 template.data.y1=self.PLOT_SETTINGS.y1 template.data.y2=self.PLOT_SETTINGS.y2 template.box1.x1=self.PLOT_SETTINGS.x1 template.box1.x2=self.PLOT_SETTINGS.x2 template.box1.y1=self.PLOT_SETTINGS.y1 template.box1.y2=self.PLOT_SETTINGS.y2 template.xname.y=self.PLOT_SETTINGS.y2+.02 template.yname.x=self.PLOT_SETTINGS.x2+.01 template.xlabel1.y=self.PLOT_SETTINGS.y1 template.xlabel2.y=self.PLOT_SETTINGS.y2 template.xlabel1.texttable=self.PLOT_SETTINGS.tictable template.xlabel2.texttable=self.PLOT_SETTINGS.tictable template.xlabel1.textorientation=self.PLOT_SETTINGS.xticorientation template.xlabel2.textorientation=self.PLOT_SETTINGS.xticorientation template.ylabel1.x=self.PLOT_SETTINGS.x1 template.ylabel2.x=self.PLOT_SETTINGS.x2 template.ylabel1.texttable=self.PLOT_SETTINGS.tictable template.ylabel2.texttable=self.PLOT_SETTINGS.tictable template.ylabel1.textorientation=self.PLOT_SETTINGS.yticorientation template.ylabel2.textorientation=self.PLOT_SETTINGS.yticorientation if self.PLOT_SETTINGS.xtic1y1 is not None: template.xtic1.y1=self.PLOT_SETTINGS.xtic1y1 template.xtic1.priority=1 if self.PLOT_SETTINGS.xtic1y2 is not None: template.xtic1.y2=self.PLOT_SETTINGS.xtic1y2 template.xtic1.priority=1 if self.PLOT_SETTINGS.xtic2y1 is not None: template.xtic2.y1=self.PLOT_SETTINGS.xtic2y1 template.xtic2.priority=1 if self.PLOT_SETTINGS.xtic2y2 is not None: template.xtic2.y2=self.PLOT_SETTINGS.xtic2y2 template.xtic2.priority=1 if self.PLOT_SETTINGS.ytic1x1 is not None: template.ytic1.x1=self.PLOT_SETTINGS.ytic1x1 template.ytic1.priority=1 if self.PLOT_SETTINGS.ytic1x2 is not None: template.ytic1.x2=self.PLOT_SETTINGS.ytic1x2 template.ytic1.priority=1 if self.PLOT_SETTINGS.ytic2x1 is not None: template.ytic2.priority=1 template.ytic2.x1=self.PLOT_SETTINGS.ytic2x1 if self.PLOT_SETTINGS.ytic2x2 is not None: template.ytic2.priority=1 template.ytic2.x2=self.PLOT_SETTINGS.ytic2x2 template.legend.x1=self.PLOT_SETTINGS.legend_x1 template.legend.x2=self.PLOT_SETTINGS.legend_x2 template.legend.y1=self.PLOT_SETTINGS.legend_y1 template.legend.y2=self.PLOT_SETTINGS.legend_y2 try: tmp = x.createtextorientation('crap22') except: tmp = x.gettextorientation('crap22') tmp.height = 12 #tmp.halign = 'center' # template.legend.texttable = tmp template.legend.textorientation = tmp else: if isinstance(template,vcs.template.P): tid=template.name elif isinstance(template,str): tid=template else: raise 'Error cannot understand what you mean by template='+str(template) template=x.createtemplate() # Do we use a predefined meshfill ? if meshfill is None: mtics={} for i in range(100): mtics[i-.5]='' icont = 1 meshfill=x.createmeshfill() meshfill.xticlabels1=eval(data.getAxis(1).names) meshfill.yticlabels1=eval(data.getAxis(0).names) meshfill.datawc_x1=-.5 meshfill.datawc_x2=data.shape[1]-.5 meshfill.datawc_y1=-.5 meshfill.datawc_y2=data.shape[0]-.5 meshfill.mesh=self.PLOT_SETTINGS.draw_mesh meshfill.missing=self.PLOT_SETTINGS.missing_color meshfill.xticlabels2=mtics meshfill.yticlabels2=mtics if self.PLOT_SETTINGS.colormap is None: self.set_colormap(x) elif x.getcolormapname()!=self.PLOT_SETTINGS.colormap: x.setcolormap(self.PLOT_SETTINGS.colormap) if self.PLOT_SETTINGS.levels is None: min,max=vcs.minmax(data) if max!=0: max=max+.000001 levs=vcs.mkscale(min,max) else: levs=self.PLOT_SETTINGS.levels if len(levs)>1: meshfill.levels=levs if self.PLOT_SETTINGS.fillareacolors is None: cols=vcs.getcolors(levs,range(16,40),split=1) meshfill.fillareacolors=cols else: meshfill.fillareacolors=self.PLOT_SETTINGS.fillareacolors ## self.setmeshfill(x,meshfill,levs) ## if self.PLOT_SETTINGS.legend is None: ## meshfill.legend=vcs.mklabels(levs) ## else: ## meshfill.legend=self.PLOT_SETTINGS.legend # Now creates the mesh associated n=int(multiple) ntot=int((multiple-n)*10+.1) ## data=data sh=list(data.shape) sh.append(2) I=MV2.indices((sh[0],sh[1])) Y=I[0] X=I[1] ## if ntot>1: ## meshfill.mesh='y' if ntot == 1: sh.append(4) M=MV2.zeros(sh) M[:,:,0,0]=Y-.5 M[:,:,1,0]=X-.5 M[:,:,0,1]=Y-.5 M[:,:,1,1]=X+.5 M[:,:,0,2]=Y+.5 M[:,:,1,2]=X+.5 M[:,:,0,3]=Y+.5 M[:,:,1,3]=X-.5 M=MV2.reshape(M,(sh[0]*sh[1],2,4)) elif ntot==2: sh.append(3) M=MV2.zeros(sh) M[:,:,0,0]=Y-.5 M[:,:,1,0]=X-.5 M[:,:,0,1]=Y+.5-(n-1) M[:,:,1,1]=X-0.5+(n-1) M[:,:,0,2]=Y+.5 M[:,:,1,2]=X+.5 M=MV2.reshape(M,(sh[0]*sh[1],2,3)) elif ntot==3: design=int((multiple-n)*100+.1) if design==33: sh.append(3) M=MV2.zeros(sh) if n==1: M[:,:,0,0]=Y-.5 M[:,:,1,0]=X-.5 M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y+.5 M[:,:,1,2]=X-.5 elif n==2: M[:,:,0,0]=Y-.5 M[:,:,1,0]=X-.5 M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y-.5 M[:,:,1,2]=X+.5 elif n==3: M[:,:,0,0]=Y+.5 M[:,:,1,0]=X+.5 M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y-.5 M[:,:,1,2]=X+.5 M=MV2.reshape(M,(sh[0]*sh[1],2,3)) elif design==32: sh.append(5) M=MV2.zeros(sh) M[:,:,0,0]=Y M[:,:,1,0]=X d=.5/MV2.sqrt(3.) if n==1: M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y+.5 M[:,:,1,2]=X-.5 M[:,:,0,3]=Y-d M[:,:,1,3]=X-.5 # dummy point for n==1 or 3 M[:,:,0,4]=Y M[:,:,1,4]=X if n==2: M[:,:,0,1]=Y-d M[:,:,1,1]=X-.5 M[:,:,0,2]=Y-.5 M[:,:,1,2]=X-.5 M[:,:,0,3]=Y-.5 M[:,:,1,3]=X+.5 M[:,:,0,4]=Y-d M[:,:,1,4]=X+.5 elif n==3: M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y+.5 M[:,:,1,2]=X+.5 M[:,:,0,3]=Y-d M[:,:,1,3]=X+.5 # dummy point for n==1 or 3 M[:,:,0,4]=Y M[:,:,1,4]=X M=MV2.reshape(M,(sh[0]*sh[1],2,5)) else: sh.append(5) M=MV2.zeros(sh) M[:,:,0,0]=Y M[:,:,1,0]=X d=1./3. if n==1: M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y+.5 M[:,:,1,2]=X-.5 M[:,:,0,3]=Y-d M[:,:,1,3]=X-.5 # dummy point for n==1 or 3 M[:,:,0,4]=Y M[:,:,1,4]=X if n==2: M[:,:,0,1]=Y-d M[:,:,1,1]=X-.5 M[:,:,0,2]=Y-.5 M[:,:,1,2]=X-.5 M[:,:,0,3]=Y-.5 M[:,:,1,3]=X+.5 M[:,:,0,4]=Y-d M[:,:,1,4]=X+.5 elif n==3: M[:,:,0,1]=Y+.5 M[:,:,1,1]=X M[:,:,0,2]=Y+.5 M[:,:,1,2]=X+.5 M[:,:,0,3]=Y-d M[:,:,1,3]=X+.5 # dummy point for n==1 or 3 M[:,:,0,4]=Y M[:,:,1,4]=X M=MV2.reshape(M,(sh[0]*sh[1],2,5)) elif ntot==4: sh.append(3) M=MV2.zeros(sh) M[:,:,0,0]=Y M[:,:,1,0]=X if n==1: M[:,:,0,1]=Y+.5 M[:,:,1,1]=X+.5 M[:,:,0,2]=Y+.5 M[:,:,1,2]=X-.5 elif n==2: M[:,:,0,1]=Y+.5 M[:,:,1,1]=X-.5 M[:,:,0,2]=Y-.5 M[:,:,1,2]=X-.5 elif n==3: M[:,:,0,1]=Y-.5 M[:,:,1,1]=X-.5 M[:,:,0,2]=Y-.5 M[:,:,1,2]=X+.5 elif n==4: M[:,:,0,1]=Y-.5 M[:,:,1,1]=X+.5 M[:,:,0,2]=Y+.5 M[:,:,1,2]=X+.5 M=MV2.reshape(M,(sh[0]*sh[1],2,3)) else: if isinstance(meshfill,vcs.meshfill.P): tid=mesh.id elif isinstance(meshfill,str): tid=mesh else: raise 'Error cannot understand what you mean by meshfill='+str(meshfill) meshfill=x.createmeshfill() if mesh is None: x.plot(MV2.ravel(data),M,template,meshfill,bg=bg) else: x.plot(MV2.ravel(data),mesh,template,meshfill,bg=bg) # Now prints the rest of the title, etc... # but only if n==1 if n==1: axes_param=[] for a in data.getAxis(0).id.split('___'): axes_param.append(a) for a in data.getAxis(1).id.split('___'): axes_param.append(a) nparam=0 for p in self.parameters_list: if not p in self.dummies and not p in self.auto_dummies and not p in axes_param: nparam+=1 if self.verbose: print 'NPARAM:',nparam if nparam>0: for i in range(nparam): j=MV2.ceil(float(nparam)/(i+1.)) if j<=i: break npc=i # number of lines npl=int(j) # number of coulmns if npc*npl<nparam : npl+=1 # computes space between each line dl=(.95-template.data.y2)/npl dc=.9/npc npci=0 # counter for columns npli=0 # counter for lines for p in self.parameters_list: if not p in self.dummies and not p in self.auto_dummies and not p in axes_param: txt=x.createtext(None,self.PLOT_SETTINGS.parametertable.name,None,self.PLOT_SETTINGS.parameterorientation.name) value=getattr(self,p) if (isinstance(value,(list,tuple)) and len(value)==1): txt.string=p+':'+str(self.makestring(p,value[0])) display=1 elif isinstance(value,(str,int,float,long)): txt.string=p+':'+str(self.makestring(p,value)) display=1 else: display=0 if display: # Now figures out where to put these... txt.x=[(npci)*dc+dc/2.+.05] txt.y=[1.-(npli)*dl-dl/2.] npci+=1 if npci>=npc: npci=0 npli+=1 if p in self.altered.keys(): dic=self.altered[p] if dic['size'] is not None: txt.size=dic['size'] if dic['color'] is not None: txt.color=dic['color'] if dic['x'] is not none: txt.x=dic['x'] if dic['y'] is not none: txt.y=dic['y'] x.plot(txt,bg=bg,continents=0) if not self.PLOT_SETTINGS.logo is None: x.plot(self.PLOT_SETTINGS.logo,bg=bg,continents=0) if not self.PLOT_SETTINGS.time_stamp is None: import time sp=time.ctime().split() sp=sp[:3]+[sp[-1]] self.PLOT_SETTINGS.time_stamp.string=''.join(sp) x.plot(self.PLOT_SETTINGS.time_stamp,bg=bg,continents=0)
def plot(self, data=None, mesh=None, template=None, meshfill=None, x=None, bg=0, multiple=1.1): # Create the vcs canvas if x is None: x = vcs.init() ## Continents bug x.setcontinentstype(0) # gets the thing to plot ! if data is None: data = self.get() # Do we use a predefined template ? if template is None: template = x.createtemplate() # Now sets all the things for the template... # Sets a bunch of template attributes to off for att in [ 'line1', 'line2', 'line3', 'line4', 'box2', 'box3', 'box4', 'min', 'max', 'mean', 'xtic1', 'xtic2', 'ytic1', 'ytic2', 'xvalue', 'yvalue', 'zvalue', 'tvalue', 'xunits', 'yunits', 'zunits', 'tunits', 'source', 'title', 'dataname', ]: a = getattr(template, att) setattr(a, 'priority', 0) for att in [ 'xname', 'yname', ]: a = getattr(template, att) setattr(a, 'priority', 0) template.data.x1 = self.PLOT_SETTINGS.x1 template.data.x2 = self.PLOT_SETTINGS.x2 template.data.y1 = self.PLOT_SETTINGS.y1 template.data.y2 = self.PLOT_SETTINGS.y2 template.box1.x1 = self.PLOT_SETTINGS.x1 template.box1.x2 = self.PLOT_SETTINGS.x2 template.box1.y1 = self.PLOT_SETTINGS.y1 template.box1.y2 = self.PLOT_SETTINGS.y2 template.xname.y = self.PLOT_SETTINGS.y2 + .02 template.yname.x = self.PLOT_SETTINGS.x2 + .01 template.xlabel1.y = self.PLOT_SETTINGS.y1 template.xlabel2.y = self.PLOT_SETTINGS.y2 template.xlabel1.texttable = self.PLOT_SETTINGS.tictable template.xlabel2.texttable = self.PLOT_SETTINGS.tictable template.xlabel1.textorientation = self.PLOT_SETTINGS.xticorientation template.xlabel2.textorientation = self.PLOT_SETTINGS.xticorientation template.ylabel1.x = self.PLOT_SETTINGS.x1 template.ylabel2.x = self.PLOT_SETTINGS.x2 template.ylabel1.texttable = self.PLOT_SETTINGS.tictable template.ylabel2.texttable = self.PLOT_SETTINGS.tictable template.ylabel1.textorientation = self.PLOT_SETTINGS.yticorientation template.ylabel2.textorientation = self.PLOT_SETTINGS.yticorientation if self.PLOT_SETTINGS.xtic1y1 is not None: template.xtic1.y1 = self.PLOT_SETTINGS.xtic1y1 template.xtic1.priority = 1 if self.PLOT_SETTINGS.xtic1y2 is not None: template.xtic1.y2 = self.PLOT_SETTINGS.xtic1y2 template.xtic1.priority = 1 if self.PLOT_SETTINGS.xtic2y1 is not None: template.xtic2.y1 = self.PLOT_SETTINGS.xtic2y1 template.xtic2.priority = 1 if self.PLOT_SETTINGS.xtic2y2 is not None: template.xtic2.y2 = self.PLOT_SETTINGS.xtic2y2 template.xtic2.priority = 1 if self.PLOT_SETTINGS.ytic1x1 is not None: template.ytic1.x1 = self.PLOT_SETTINGS.ytic1x1 template.ytic1.priority = 1 if self.PLOT_SETTINGS.ytic1x2 is not None: template.ytic1.x2 = self.PLOT_SETTINGS.ytic1x2 template.ytic1.priority = 1 if self.PLOT_SETTINGS.ytic2x1 is not None: template.ytic2.priority = 1 template.ytic2.x1 = self.PLOT_SETTINGS.ytic2x1 if self.PLOT_SETTINGS.ytic2x2 is not None: template.ytic2.priority = 1 template.ytic2.x2 = self.PLOT_SETTINGS.ytic2x2 template.legend.x1 = self.PLOT_SETTINGS.legend_x1 template.legend.x2 = self.PLOT_SETTINGS.legend_x2 template.legend.y1 = self.PLOT_SETTINGS.legend_y1 template.legend.y2 = self.PLOT_SETTINGS.legend_y2 try: tmp = x.createtextorientation('crap22') except: tmp = x.gettextorientation('crap22') tmp.height = 12 #tmp.halign = 'center' # template.legend.texttable = tmp template.legend.textorientation = tmp else: if isinstance(template, vcs.template.P): tid = template.name elif isinstance(template, str): tid = template else: raise 'Error cannot understand what you mean by template=' + str( template) template = x.createtemplate() # Do we use a predefined meshfill ? if meshfill is None: mtics = {} for i in range(100): mtics[i - .5] = '' icont = 1 meshfill = x.createmeshfill() meshfill.xticlabels1 = eval(data.getAxis(1).names) meshfill.yticlabels1 = eval(data.getAxis(0).names) meshfill.datawc_x1 = -.5 meshfill.datawc_x2 = data.shape[1] - .5 meshfill.datawc_y1 = -.5 meshfill.datawc_y2 = data.shape[0] - .5 meshfill.mesh = self.PLOT_SETTINGS.draw_mesh meshfill.missing = self.PLOT_SETTINGS.missing_color meshfill.xticlabels2 = mtics meshfill.yticlabels2 = mtics if self.PLOT_SETTINGS.colormap is None: self.set_colormap(x) elif x.getcolormapname() != self.PLOT_SETTINGS.colormap: x.setcolormap(self.PLOT_SETTINGS.colormap) if self.PLOT_SETTINGS.levels is None: min, max = vcs.minmax(data) if max != 0: max = max + .000001 levs = vcs.mkscale(min, max) else: levs = self.PLOT_SETTINGS.levels if len(levs) > 1: meshfill.levels = levs if self.PLOT_SETTINGS.fillareacolors is None: cols = vcs.getcolors(levs, range(16, 40), split=1) meshfill.fillareacolors = cols else: meshfill.fillareacolors = self.PLOT_SETTINGS.fillareacolors ## self.setmeshfill(x,meshfill,levs) ## if self.PLOT_SETTINGS.legend is None: ## meshfill.legend=vcs.mklabels(levs) ## else: ## meshfill.legend=self.PLOT_SETTINGS.legend # Now creates the mesh associated n = int(multiple) ntot = int((multiple - n) * 10 + .1) ## data=data sh = list(data.shape) sh.append(2) I = MV2.indices((sh[0], sh[1])) Y = I[0] X = I[1] ## if ntot>1: ## meshfill.mesh='y' if ntot == 1: sh.append(4) M = MV2.zeros(sh) M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y + .5 M[:, :, 1, 3] = X - .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 4)) elif ntot == 2: sh.append(3) M = MV2.zeros(sh) M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 - (n - 1) M[:, :, 1, 1] = X - 0.5 + (n - 1) M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) elif ntot == 3: design = int((multiple - n) * 100 + .1) if design == 33: sh.append(3) M = MV2.zeros(sh) if n == 1: M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 elif n == 2: M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 elif n == 3: M[:, :, 0, 0] = Y + .5 M[:, :, 1, 0] = X + .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) elif design == 32: sh.append(5) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X d = .5 / MV2.sqrt(3.) if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X - .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X if n == 2: M[:, :, 0, 1] = Y - d M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - .5 M[:, :, 1, 3] = X + .5 M[:, :, 0, 4] = Y - d M[:, :, 1, 4] = X + .5 elif n == 3: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X + .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X M = MV2.reshape(M, (sh[0] * sh[1], 2, 5)) else: sh.append(5) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X d = 1. / 3. if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X - .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X if n == 2: M[:, :, 0, 1] = Y - d M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - .5 M[:, :, 1, 3] = X + .5 M[:, :, 0, 4] = Y - d M[:, :, 1, 4] = X + .5 elif n == 3: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X + .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X M = MV2.reshape(M, (sh[0] * sh[1], 2, 5)) elif ntot == 4: sh.append(3) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 elif n == 2: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 elif n == 3: M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 elif n == 4: M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) else: if isinstance(meshfill, vcs.meshfill.P): tid = mesh.id elif isinstance(meshfill, str): tid = mesh else: raise 'Error cannot understand what you mean by meshfill=' + str( meshfill) meshfill = x.createmeshfill() if mesh is None: x.plot(MV2.ravel(data), M, template, meshfill, bg=bg) else: x.plot(MV2.ravel(data), mesh, template, meshfill, bg=bg) # Now prints the rest of the title, etc... # but only if n==1 if n == 1: axes_param = [] for a in data.getAxis(0).id.split('___'): axes_param.append(a) for a in data.getAxis(1).id.split('___'): axes_param.append(a) nparam = 0 for p in self.parameters_list: if not p in self.dummies and not p in self.auto_dummies and not p in axes_param: nparam += 1 if self.verbose: print 'NPARAM:', nparam if nparam > 0: for i in range(nparam): j = MV2.ceil(float(nparam) / (i + 1.)) if j <= i: break npc = i # number of lines npl = int(j) # number of coulmns if npc * npl < nparam: npl += 1 # computes space between each line dl = (.95 - template.data.y2) / npl dc = .9 / npc npci = 0 # counter for columns npli = 0 # counter for lines for p in self.parameters_list: if not p in self.dummies and not p in self.auto_dummies and not p in axes_param: txt = x.createtext( None, self.PLOT_SETTINGS.parametertable.name, None, self.PLOT_SETTINGS.parameterorientation.name) value = getattr(self, p) if (isinstance(value, (list, tuple)) and len(value) == 1): txt.string = p + ':' + str( self.makestring(p, value[0])) display = 1 elif isinstance(value, (str, int, float, long)): txt.string = p + ':' + str( self.makestring(p, value)) display = 1 else: display = 0 if display: # Now figures out where to put these... txt.x = [(npci) * dc + dc / 2. + .05] txt.y = [1. - (npli) * dl - dl / 2.] npci += 1 if npci >= npc: npci = 0 npli += 1 if p in self.altered.keys(): dic = self.altered[p] if dic['size'] is not None: txt.size = dic['size'] if dic['color'] is not None: txt.color = dic['color'] if dic['x'] is not none: txt.x = dic['x'] if dic['y'] is not none: txt.y = dic['y'] x.plot(txt, bg=bg, continents=0) if not self.PLOT_SETTINGS.logo is None: x.plot(self.PLOT_SETTINGS.logo, bg=bg, continents=0) if not self.PLOT_SETTINGS.time_stamp is None: import time sp = time.ctime().split() sp = sp[:3] + [sp[-1]] self.PLOT_SETTINGS.time_stamp.string = ''.join(sp) x.plot(self.PLOT_SETTINGS.time_stamp, bg=bg, continents=0)
def plot(self, data=None, mesh=None, template=None, meshfill=None, x=None, bg=0, multiple=1.1): self.bg = bg # Create the vcs canvas if x is not None: self.x = x # Continents bug # x.setcontinentstype(0) # gets the thing to plot ! if data is None: data = self.get() # Do we use a predefined template ? if template is None: template = self.generateTemplate() else: if isinstance(template, vcs.template.P): tid = template.name elif isinstance(template, str): tid = template else: raise 'Error cannot understand what you mean by template=' + \ str(template) template = vcs.createtemplate(source=tid) # Do we use a predefined meshfill ? if meshfill is None: mtics = {} for i in range(100): mtics[i - .5] = '' meshfill = vcs.createmeshfill() meshfill.xticlabels1 = eval(data.getAxis(1).names) meshfill.yticlabels1 = eval(data.getAxis(0).names) meshfill.datawc_x1 = -.5 meshfill.datawc_x2 = data.shape[1] - .5 meshfill.datawc_y1 = -.5 meshfill.datawc_y2 = data.shape[0] - .5 meshfill.mesh = self.PLOT_SETTINGS.draw_mesh meshfill.missing = self.PLOT_SETTINGS.missing_color meshfill.xticlabels2 = mtics meshfill.yticlabels2 = mtics if self.PLOT_SETTINGS.colormap is None: self.set_colormap() elif self.x.getcolormapname() != self.PLOT_SETTINGS.colormap: self.x.setcolormap(self.PLOT_SETTINGS.colormap) if self.PLOT_SETTINGS.levels is None: min, max = vcs.minmax(data) if max != 0: max = max + .000001 levs = vcs.mkscale(min, max) else: levs = self.PLOT_SETTINGS.levels if len(levs) > 1: meshfill.levels = levs if self.PLOT_SETTINGS.fillareacolors is None: if self.PLOT_SETTINGS.colormap is None: # Default colormap only use range 16->40 cols = vcs.getcolors(levs, list(range(16, 40)), split=1) else: cols = vcs.getcolors(levs, split=1) meshfill.fillareacolors = cols else: meshfill.fillareacolors = self.PLOT_SETTINGS.fillareacolors # Now creates the mesh associated n = int(multiple) ntot = int((multiple - n) * 10 + .1) sh = list(data.shape) sh.append(2) Indx = MV2.indices((sh[0], sh[1])) Y = Indx[0] X = Indx[1] if ntot == 1: sh.append(4) M = MV2.zeros(sh) M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y + .5 M[:, :, 1, 3] = X - .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 4)) elif ntot == 2: sh.append(3) M = MV2.zeros(sh) M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 - (n - 1) M[:, :, 1, 1] = X - 0.5 + (n - 1) M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) elif ntot == 3: design = int((multiple - n) * 100 + .1) if design == 33: sh.append(3) M = MV2.zeros(sh) if n == 1: M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 elif n == 2: M[:, :, 0, 0] = Y - .5 M[:, :, 1, 0] = X - .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 elif n == 3: M[:, :, 0, 0] = Y + .5 M[:, :, 1, 0] = X + .5 M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) elif design == 32: sh.append(5) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X d = .5 / MV2.sqrt(3.) if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X - .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X if n == 2: M[:, :, 0, 1] = Y - d M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - .5 M[:, :, 1, 3] = X + .5 M[:, :, 0, 4] = Y - d M[:, :, 1, 4] = X + .5 elif n == 3: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X + .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X M = MV2.reshape(M, (sh[0] * sh[1], 2, 5)) else: sh.append(5) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X d = 1. / 3. if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X - .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X if n == 2: M[:, :, 0, 1] = Y - d M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 M[:, :, 0, 3] = Y - .5 M[:, :, 1, 3] = X + .5 M[:, :, 0, 4] = Y - d M[:, :, 1, 4] = X + .5 elif n == 3: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M[:, :, 0, 3] = Y - d M[:, :, 1, 3] = X + .5 # dummy point for n==1 or 3 M[:, :, 0, 4] = Y M[:, :, 1, 4] = X M = MV2.reshape(M, (sh[0] * sh[1], 2, 5)) elif ntot == 4: sh.append(3) M = MV2.zeros(sh) M[:, :, 0, 0] = Y M[:, :, 1, 0] = X if n == 1: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X - .5 elif n == 2: M[:, :, 0, 1] = Y + .5 M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X - .5 elif n == 3: M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X - .5 M[:, :, 0, 2] = Y - .5 M[:, :, 1, 2] = X + .5 elif n == 4: M[:, :, 0, 1] = Y - .5 M[:, :, 1, 1] = X + .5 M[:, :, 0, 2] = Y + .5 M[:, :, 1, 2] = X + .5 M = MV2.reshape(M, (sh[0] * sh[1], 2, 3)) else: if isinstance(meshfill, vcs.meshfill.P): tid = mesh.id elif isinstance(meshfill, str): tid = mesh else: raise 'Error cannot understand what you mean by meshfill=' + \ str(meshfill) meshfill = vcs.createmeshfill(source=tid) if mesh is None: mesh = M raveled = MV2.ravel(data) self.x.plot(raveled, mesh, template, meshfill, bg=self.bg) # If required plot values if self.PLOT_SETTINGS.values.show: self.draw_values(raveled, mesh, meshfill, template) # Now prints the rest of the title, etc... # but only if n==1 if n == 1: axes_param = [] for a in data.getAxis(0).id.split('___'): axes_param.append(a) for a in data.getAxis(1).id.split('___'): axes_param.append(a) nparam = 0 for p in self.parameters_list: if p not in self.dummies and \ p not in self.auto_dummies and \ p not in axes_param: nparam += 1 if self.verbose: print('NPARAM:', nparam) if nparam > 0: for i in range(nparam): j = MV2.ceil(float(nparam) / (i + 1.)) if j <= i: break npc = i # number of lines npl = int(j) # number of coulmns if npc * npl < nparam: npl += 1 # computes space between each line dl = (.95 - template.data.y2) / npl dc = .9 / npc npci = 0 # counter for columns npli = 0 # counter for lines for p in self.parameters_list: if p not in self.dummies and \ p not in self.auto_dummies and \ p not in axes_param: txt = self.x.createtext( None, self.PLOT_SETTINGS.parametertable.name, None, self.PLOT_SETTINGS.parameterorientation.name) value = getattr(self, p) if (isinstance(value, (list, tuple)) and len(value) == 1): txt.string = p + ':' + \ str(self.makestring(p, value[0])) display = 1 elif isinstance(value, (str, int, float)): txt.string = p + ':' + \ str(self.makestring(p, value)) display = 1 else: display = 0 if display: # Now figures out where to put these... txt.x = [(npci) * dc + dc / 2. + .05] txt.y = [1. - (npli) * dl - dl / 2.] npci += 1 if npci >= npc: npci = 0 npli += 1 if p in list(self.altered.keys()): dic = self.altered[p] if dic['size'] is not None: txt.size = dic['size'] if dic['color'] is not None: txt.color = dic['color'] if dic['x'] is not None: txt.x = dic['x'] if dic['y'] is not None: txt.y = dic['y'] self.x.plot(txt, bg=self.bg, continents=0) if self.PLOT_SETTINGS.time_stamp is not None: sp = time.ctime().split() sp = sp[:3] + [sp[-1]] self.PLOT_SETTINGS.time_stamp.string = ''.join(sp) self.x.plot( self.PLOT_SETTINGS.time_stamp, bg=self.bg, continents=0) if self.PLOT_SETTINGS.logo is not None: self.PLOT_SETTINGS.logo.plot(self.x, bg=self.bg) return mesh, template, meshfill