def addtext(txt,xy=None,fontsize=16,font='helvetica',color='black', orient=0,justify='LA',tosys=0): if xy is None: result = gist.mouse(0,0,"Click on point for lower left starting position") if result is None: raise ValueError, "Invalid point entered." x,y = result[4],result[5] tosys = 0 else: x,y = xy if isinstance(txt, type('')) and txt != '': gist.plt(txt, x, y, tosys=tosys, justify=justify, height=fontsize,font=font, color=color, orient=orient) return
def legend(text,linetypes=None,lleft=None,color=None,tfont='helvetica',fontsize=14,nobox=0): """Construct and place a legend. Description: Build a legend and place it on the current plot with an interactive prompt. Inputs: text -- A list of strings which document the curves. linetypes -- If not given, then the text strings are associated with the curves in the order they were originally drawn. Otherwise, associate the text strings with the corresponding curve types given. See plot for description. """ global _hold global _textcolor if color is None: color = _textcolor else: _textcolor = color if color is None: color = 'black' sys = gist.plsys() if sys == 0: gist.plsys(1) viewp = gist.viewport() gist.plsys(sys) DX = viewp[1] - viewp[0] DY = viewp[3] - viewp[2] width = DY / 10.0; if lleft is None: lleft = gist.mouse(0,0,"Click on point for lower left coordinate.") llx = lleft[0] lly = lleft[1] else: llx,lly = lleft[:2] savesys = gist.plsys() dx = width / 3.0 legarr = Numeric.arange(llx,llx+width,dx) legy = Numeric.ones(legarr.shape) dy = fontsize*points*1.2 deltay = fontsize*points / 2.8 deltax = fontsize*points / 2.6 * DX / DY ypos = lly + deltay; if linetypes is None: linetypes = _GLOBAL_LINE_TYPES[:] # copy them out gist.plsys(0) savehold = _hold _hold = 1 for k in range(len(text)): plot(legarr,ypos*legy,linetypes[k]) print linetypes[k], text[k] print llx+width+deltax, ypos-deltay if text[k] != "": gist.plt(text[k],llx+width+deltax,ypos-deltay, color=color,font=tfont,height=fontsize,tosys=0) ypos = ypos + dy _hold = savehold if nobox: pass else: gist.plsys(0) maxlen = MLab.max(map(len,text)) c1 = (llx-deltax,lly-deltay) c2 = (llx + width + deltax + fontsize*points* maxlen/1.8 + deltax, lly + len(text)*dy) linesx0 = [c1[0],c1[0],c2[0],c2[0]] linesy0 = [c1[1],c2[1],c2[1],c1[1]] linesx1 = [c1[0],c2[0],c2[0],c1[0]] linesy1 = [c2[1],c2[1],c1[1],c1[1]] gist.pldj(linesx0,linesy0,linesx1,linesy1,color=color) gist.plsys(savesys) return
def legend(text,linetypes=None,lleft=None,color=None,tfont='helvetica',fontsize=14,nobox=0): """Construct and place a legend. Description: Build a legend and place it on the current plot with an interactive prompt. Inputs: text -- A list of strings which document the curves. linetypes -- If not given, then the text strings are associated with the curves in the order they were originally drawn. Otherwise, associate the text strings with the corresponding curve types given. See plot for description. """ global _hold global _textcolor if color is None: color = _textcolor else: _textcolor = color if color is None: color = 'black' sys = gist.plsys() if sys == 0: gist.plsys(1) viewp = gist.viewport() gist.plsys(sys) DX = viewp[1] - viewp[0] DY = viewp[3] - viewp[2] width = DY / 10.0; if lleft is None: lleft = gist.mouse(0,0,"Click on point for lower left coordinate.") llx = lleft[0] lly = lleft[1] else: llx,lly = lleft[:2] savesys = gist.plsys() dx = width / 3.0 legarr = numpy.arange(llx,llx+width,dx) legy = numpy.ones(legarr.shape) dy = fontsize*points*1.2 deltay = fontsize*points / 2.8 deltax = fontsize*points / 2.6 * DX / DY ypos = lly + deltay; if linetypes is None: linetypes = _GLOBAL_LINE_TYPES[:] # copy them out gist.plsys(0) savehold = _hold _hold = 1 for k in range(len(text)): plot(legarr,ypos*legy,linetypes[k]) print linetypes[k], text[k] print llx+width+deltax, ypos-deltay if text[k] != "": gist.plt(text[k],llx+width+deltax,ypos-deltay, color=color,font=tfont,height=fontsize,tosys=0) ypos = ypos + dy _hold = savehold if nobox: pass else: gist.plsys(0) maxlen = numpy.max(map(len,text)) c1 = (llx-deltax,lly-deltay) c2 = (llx + width + deltax + fontsize*points* maxlen/1.8 + deltax, lly + len(text)*dy) linesx0 = [c1[0],c1[0],c2[0],c2[0]] linesy0 = [c1[1],c2[1],c2[1],c1[1]] linesx1 = [c1[0],c2[0],c2[0],c1[0]] linesy1 = [c2[1],c2[1],c1[1],c1[1]] gist.pldj(linesx0,linesy0,linesx1,linesy1,color=color) gist.plsys(savesys) return