def title3(text,color=None,font='helvetica',fontsize=18,deltax=0.0,deltay=0.0): global _textcolor if color is None: color = _textcolor else: _textcolor = color if color is None: color = 'black' vp = gist.viewport() xmidpt = (vp[0] + vp[1])/2.0 + deltax if text != "": gist.plt(text,xmidpt,vp[3]-0.05-deltay, font=font, justify='CB', height=fontsize, color=color)
def arrow(x0,y0,x1,y1,color=0,ang=45.0,height=6,width=1.5,lc=None): """Draw an arrow. Description: Draw an arrow from (x0,y0) to (x1,y1) in the current coordinate system. Inputs: x0, y0 -- The beginning point. x1, y1 -- Then ending point. color -- The color of the arrowhead. Number represents an index in the current palette or a negative number or a spelled out basic color. lc -- The color of the line (same as color by default). ang -- The angle of the arrowhead. height -- The height of the arrowhead in points. width -- The width of the arrow line in points. """ if lc is None: lc = color if type(lc) is types.StringType: lc = _colornum[lc] if type(color) is types.StringType: color = _colornum[color] vp = gist.viewport() plotlims = gist.limits() gist.limits(plotlims) conv_factorx = (vp[1]-vp[0]) / (plotlims[1]-plotlims[0]) conv_factory = (vp[3]-vp[2]) / (plotlims[3]-plotlims[2]) ang = ang*pi/180 height = height*points hypot = height / cos(ang) difx = (x1 - x0) * conv_factorx dify = (y1 - y0) * conv_factory theta = arctan2(dify,difx) + pi tha = theta + ang thb = theta - ang x1a = x1 + hypot*cos(tha) / conv_factorx x1b = x1 + hypot*cos(thb) / conv_factorx y1a = y1 + hypot*sin(tha) / conv_factory y1b = y1 + hypot*sin(thb) / conv_factory gist.pldj([x0],[y0],[x1],[y1],color=lc,width=width) gist.plfp(array([color],'B'),[y1,y1a,y1b],[x1,x1a,x1b],[3]) return
def errorbars(x,y,err,ptcolor='r',linecolor='B',pttype='o',linetype='-',fac=0.25): """Draw connected points with errorbars. Description: Plot connected points with errorbars. Inputs: x, y -- The points to plot. err -- The error in the y values. ptcolor -- The color for the points. linecolor -- The color of the connecting lines and error bars. pttype -- The type of point ('o', 'x', '+', '.', 'x', '*') linetype -- The type of line ('-', '|', ':', '-.', '-:') fac -- Adjusts how long the horizontal lines are which make the top and bottom of the error bars. """ # create line arrays yb = y - err ye = y + err try: override = 1 savesys = gist.plsys(2) gist.plsys(savesys) except: override = 0 if _hold or override: pass else: gist.fma() y = where(numpy.isfinite(y),y,0) gist.plg(y,x,color=_colors[ptcolor],marker=_markers[pttype],type='none') gist.pldj(x,yb,x,ye,color=_colors[linecolor],type=_types[linetype]) viewp = gist.viewport() plotlims = gist.limits() conv_factorx = (viewp[1] - viewp[0]) / (plotlims[1]-plotlims[0]) conv_factory = (viewp[3] - viewp[2]) / (plotlims[3]-plotlims[2]) width = fac*(x[1]-x[0]) x0 = x-width/2.0 x1 = x+width/2.0 gist.pldj(x0,ye,x1,ye,color=_colors[linecolor],type=_types[linetype]) gist.pldj(x0,yb,x1,yb,color=_colors[linecolor],type=_types[linetype]) return
def ylabel(text,color=None,font='helvetica',fontsize=16,deltax=0.0,deltay=0.0): """To get symbol font for the next character precede by !. To get superscript enclose with ^^ To get subscript enclose with _<text>_ """ global _textcolor if color is None: color = _textcolor else: _textcolor = color if color is None: color = 'black' vp = gist.viewport() ymidpt = (vp[2] + vp[3])/2.0 + deltay x0 = vp[0] - 0.055 + deltax if text != "": gist.plt(text, x0, ymidpt, color=color, font=font, justify="CB", height=fontsize, orient=1) return x0, ymidpt
def title(text,color=None,font='helvetica',fontsize=18,deltax=0.0,deltay=0.0): """Set title for plot. To get symbol font for the next character precede by !. To get superscript enclose with ^^ To get subscript enclose with _<text>_ """ global _textcolor if color is None: color = _textcolor else: _textcolor = color if color is None: color = 'black' vp = gist.viewport() xmidpt = (vp[0] + vp[1])/2.0 + deltax if text != "": gist.plt(text,xmidpt,vp[3] + 0.02 + deltay, font=font, justify='CB', height=fontsize, color=color)
def matview(A,cmax=None,cmin=None,palette=None,color='black'): """Plot an image of a matrix. """ A = Numeric.asarray(A) if A.dtype.char in ['D','F']: print "Warning: complex array given, plotting magnitude." A = abs(A) M,N = A.shape A = A[::-1,:] if cmax is None: cmax = max(ravel(A)) if cmin is None: cmin = min(ravel(A)) cmax = float(cmax) cmin = float(cmin) byteimage = gist.bytscl(A,cmin=cmin,cmax=cmax) change_palette(palette) gist.window(style='nobox.gs') _current_style='nobox.gs' gist.pli(byteimage) old_vals = gist.limits(square=1) vals = gist.limits(square=1) if color is None: return vp = gist.viewport() axv,bxv,ayv,byv = vp axs,bxs,ays,bys = vals[:4] # bottom left corner column posy = -ays*(byv-ayv)/(bys-ays) + ayv posx = -axs*(bxv-axv)/(bxs-axs) + axv gist.plt('b',posx,posy-0.005,justify='LT',color=color) # bottom left corner row gist.plt(str(M),posx-0.005,posy,justify='RB',color=color) # top left corner row posy = (M-ays)*(byv-ayv)/(bys-ays) + ayv gist.plt('b',posx-0.005,posy,justify='RT',color=color) # bottom right column posy = -ays*(byv-ayv)/(bys-ays) + ayv posx = (N-axs)*(bxv-axv)/(bxs-axs) + axv gist.plt(str(N),posx,posy-0.005,justify='RT',color=color)
def matview(A,cmax=None,cmin=None,palette=None,color='black'): """Plot an image of a matrix. """ A = numpy.asarray(A) if A.dtype.char in ['D','F']: print "Warning: complex array given, plotting magnitude." A = abs(A) M,N = A.shape A = A[::-1,:] if cmax is None: cmax = max(ravel(A)) if cmin is None: cmin = min(ravel(A)) cmax = float(cmax) cmin = float(cmin) byteimage = gist.bytscl(A,cmin=cmin,cmax=cmax) change_palette(palette) gist.window(style='nobox.gs') _current_style='nobox.gs' gist.pli(byteimage) old_vals = gist.limits(square=1) vals = gist.limits(square=1) if color is None: return vp = gist.viewport() axv,bxv,ayv,byv = vp axs,bxs,ays,bys = vals[:4] # bottom left corner column posy = -ays*(byv-ayv)/(bys-ays) + ayv posx = -axs*(bxv-axv)/(bxs-axs) + axv gist.plt('b',posx,posy-0.005,justify='LT',color=color) # bottom left corner row gist.plt(str(M),posx-0.005,posy,justify='RB',color=color) # top left corner row posy = (M-ays)*(byv-ayv)/(bys-ays) + ayv gist.plt('b',posx-0.005,posy,justify='RT',color=color) # bottom right column posy = -ays*(byv-ayv)/(bys-ays) + ayv posx = (N-axs)*(bxv-axv)/(bxs-axs) + axv gist.plt(str(N),posx,posy-0.005,justify='RT',color=color)
def stem(m, y, linetype='b-', mtype='mo', shift=0.013): y0 = Numeric.zeros(len(y),y.dtype.char) y1 = y x0 = m x1 = m try: override = 1 savesys = gist.plsys(2) gist.plsys(savesys) except: override = 0 if not (_hold or override): gist.fma() thetype,thecolor,themarker,tomark = _parse_type_arg(linetype,0) lcolor = thecolor gist.pldj(x0, y0, x1, y1, color=thecolor, type=thetype) thetype,thecolor,themarker,tomark = _parse_type_arg(mtype,0) if themarker not in ['o','x','.','*']: themarker = 'o' y = where(numpy.isfinite(y),y,0) gist.plg(y,m,color=thecolor,marker=themarker,type='none') gist.plg(Numeric.zeros(len(m)),m,color=lcolor,marks=0) gist.limits() lims = gist.limits() newlims = [None]*4 vp = gist.viewport() factor1 = vp[1] - vp[0] factor2 = vp[3] - vp[2] cfactx = factor1 / (lims[1] - lims[0]) cfacty = factor2 / (lims[3] - lims[2]) d1 = shift / cfactx d2 = shift / cfacty newlims[0] = lims[0] - d1 newlims[1] = lims[1] + d1 newlims[2] = lims[2] - d2 newlims[3] = lims[3] + d2 gist.limits(*newlims) return
def stem(m, y, linetype='b-', mtype='mo', shift=0.013): y0 = numpy.zeros(len(y),y.dtype.char) y1 = y x0 = m x1 = m try: override = 1 savesys = gist.plsys(2) gist.plsys(savesys) except: override = 0 if not (_hold or override): gist.fma() thetype,thecolor,themarker,tomark = _parse_type_arg(linetype,0) lcolor = thecolor gist.pldj(x0, y0, x1, y1, color=thecolor, type=thetype) thetype,thecolor,themarker,tomark = _parse_type_arg(mtype,0) if themarker not in ['o','x','.','*']: themarker = 'o' y = where(numpy.isfinite(y),y,0) gist.plg(y,m,color=thecolor,marker=themarker,type='none') gist.plg(numpy.zeros(len(m)),m,color=lcolor,marks=0) gist.limits() lims = gist.limits() newlims = [None]*4 vp = gist.viewport() factor1 = vp[1] - vp[0] factor2 = vp[3] - vp[2] cfactx = factor1 / (lims[1] - lims[0]) cfacty = factor2 / (lims[3] - lims[2]) d1 = shift / cfactx d2 = shift / cfacty newlims[0] = lims[0] - d1 newlims[1] = lims[1] + d1 newlims[2] = lims[2] - d2 newlims[3] = lims[3] + d2 gist.limits(*newlims) 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