Exemple #1
0
def mysurf(z,x=None,y=None,win=None,shade=0,edges=1,edge_color="black",phi=-45.0,
         theta=30.0,zscale=1.0,palette=None,gnomon=0,animate=False,limits=True, ireg=None):
    """Plot a three-dimensional wire-frame (surface): z=f(x,y)
    """
    if win is None:
    	  pass
        #pl3d.window3()
    else:
        pl3d.window3(win)
    pl3d.set_draw3_(0)
    phi0 = phi*pi/180.0
    theta0 = theta*pi/180.0
    pl3d.orient3(phi=phi0,theta=theta0)
    pl3d.light3()
    change_palette(palette)
    sz = numpy.shape(z)
    if len(sz) != 2:
        raise ValueError, "Input must be a 2-d array --- a surface."
    N,M = sz
    if x is None:
        x = arange(0,N)
    if y is None:
        y = arange(0,M)
    x = numpy.squeeze(x)
    y = numpy.squeeze(y)
    if (len(numpy.shape(x)) == 1):
        x = x[:,newaxis]*ones((1,M))
    if (len(numpy.shape(y)) == 1):
        y = ones((N,1))*y[newaxis,:]
    plwf.plwf(z,y,x,shade=shade,edges=edges,ecolor=edge_color,scale=zscale, ireg=ireg)
    # if animate, the application is responsible to fma
    lims = pl3d.draw3(not animate)
    if limits:
      gist.limits(lims[0],lims[1],lims[2],lims[3])
    pl3d.gnomon(gnomon)
Exemple #2
0
def surf(z,x=None,y=None,win=None,shade=0,edges=1,edge_color="black",phi=-45.0,
         theta=30.0,zscale=1.0,palette=None,gnomon=0):
    """Plot a three-dimensional wire-frame (surface): z=f(x,y)
    """
    if win is None:
        pl3d.window3()
    else:
        pl3d.window3(win)
    pl3d.set_draw3_(0)
    phi0 = phi*pi/180.0
    theta0 = theta*pi/180.0
    pl3d.orient3(phi=phi0,theta=theta0)
    pl3d.light3()
    change_palette(palette)
    sz = numpy.shape(z)
    if len(sz) != 2:
        raise ValueError, "Input must be a 2-d array --- a surface."
    N,M = sz
    if x is None:
        x = arange(0,N)
    if y is None:
        y = arange(0,M)
    x = numpy.squeeze(x)
    y = numpy.squeeze(y)
    if (len(numpy.shape(x)) == 1):
        x = x[:,newaxis]*ones((1,M))
    if (len(numpy.shape(y)) == 1):
        y = ones((N,1))*y[newaxis,:]
    plwf.plwf(z,y,x,shade=shade,edges=edges,ecolor=edge_color,scale=zscale)
    lims = pl3d.draw3(1)
    gist.limits(lims[0],lims[1],lims[2],lims[3])
    pl3d.gnomon(gnomon)
Exemple #3
0
def axes(type='b|'):
    vals = gist.limits()
    v0,v1,v2,v3 = vals[:4]
    x0 = numpy.r_[v0:v1:5j]
    y0 = 5*[0]
    x1 = 5*[0]
    y1 = numpy.r_[v2:v3:5j]
    plot(x0,y0,type,x1,y1,type,hold=1)
    gist.limits(v0,v1,v2,v3)
Exemple #4
0
def axes(type='b|'):
    vals = gist.limits()
    v0,v1,v2,v3 = vals[:4]
    x0 = numpy.r_[v0:v1:5j]
    y0 = 5*[0]
    x1 = 5*[0]
    y1 = numpy.r_[v2:v3:5j]
    plot(x0,y0,type,x1,y1,type,hold=1)
    gist.limits(v0,v1,v2,v3)
Exemple #5
0
    def _plot(self):
        import gist

        gist.window(self.id, wait=1)
        gist.animate(1)
        gist.pltitle(self.title)
        gist.palette(self.palette)
        gist.gridxy(self.grid)

        if self.limits != None:
            gist.limits(self._getLimit('xmin'), self._getLimit('xmax'),
                        self._getLimit('ymin'), self._getLimit('ymax'))
Exemple #6
0
def expand_limits(xpcnt,ypcnt=None):
    """Expand the limits by a certain percentage.
    """
    if ypcnt is None:
        ypcnt = xpcnt
    if xpcnt > 1:
        xpcnt = xpcnt / 100.0
    if ypcnt > 1:
        ypcnt = ypcnt / 100.0
    xmin, xmax, ymin, ymax, flag = gist.limits()
    dx = (xmax-xmin)*xpcnt/2.0
    dy = (ymax-ymin)*ypcnt/2.0
    gist.limits(xmin-dx,xmax+dx,ymin-dy,ymax+dy)
Exemple #7
0
def expand_limits(xpcnt,ypcnt=None):
    """Expand the limits by a certain percentage.
    """
    if ypcnt is None:
        ypcnt = xpcnt
    if xpcnt > 1:
        xpcnt = xpcnt / 100.0
    if ypcnt > 1:
        ypcnt = ypcnt / 100.0
    xmin, xmax, ymin, ymax, flag = gist.limits()
    dx = (xmax-xmin)*xpcnt/2.0
    dy = (ymax-ymin)*ypcnt/2.0
    gist.limits(xmin-dx,xmax+dx,ymin-dy,ymax+dy)
Exemple #8
0
    def _plot(self):
        import gist
    
        gist.window(self.id, wait = 1)
        gist.animate(1)
        gist.pltitle(self.title)
        gist.palette(self.palette)
        gist.gridxy(self.grid)

        if self.limits != None:
            gist.limits(self._getLimit('xmin'), 
                        self._getLimit('xmax'), 
                        self._getLimit('ymin'), 
                        self._getLimit('ymax'))
    def plot(self, filename=None):
        import gist

        gist.window(self.id, wait=1, style=self.style)
        gist.pltitle(self.title)
        gist.animate(1)

        if self.limits != None:
            gist.limits(self._getLimit('xmin'), self._getLimit('xmax'),
                        self._getLimit(('datamin', 'ymin')),
                        self._getLimit(('datamax', 'ymax')))

        self._plotArrays()

        _GistViewer.plot(self, filename=filename)
Exemple #10
0
    def plot(self, filename = None):
        import gist

        gist.window(self.id, wait = 1, style = self.style)
        gist.pltitle(self.title)
        gist.animate(1)

        if self.limits != None:
            gist.limits(self._getLimit('xmin'), 
                        self._getLimit('xmax'), 
                        self._getLimit(('datamin', 'ymin')), 
                        self._getLimit(('datamax', 'ymax')))
            
        self._plotArrays()
            
        _GistViewer.plot(self, filename = filename)
Exemple #11
0
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
Exemple #12
0
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
Exemple #13
0
def run(arrow_scales=True):
  gist.fma()

  # generate a random field

  test_dim=10

  dx=numpy.random.rand(test_dim**2)-0.5
  dy=numpy.random.rand(test_dim**2)-0.5
  p=numpy.indices((test_dim,test_dim))
  x=p[0].ravel()
  y=p[1].ravel()

  X1=x
  Y1=y
  X2=x+dx
  Y2=y+dy
  gist.pldj(X1,Y1,X2,Y2)

  arrow_a = numpy.pi/6.
  arrow_len = .5

  slo=(Y2-Y1)/(X2-X1)
  ang=numpy.arctan(slo)
  ang1=ang+arrow_a
  ang2=ang-arrow_a

  if arrow_scales:
     ar_=numpy.sign(X2-X1)*arrow_len*((X2-X1)**2+(Y2-Y1)**2)
     aX1=X2-ar_*numpy.cos(ang1)
     aY1=Y2-ar_*numpy.sin(ang1)
     aX2=X2-ar_*numpy.cos(ang2)
     aY2=Y2-ar_*numpy.sin(ang2)
  else:
     ar_=numpy.sign(X2-X1)*arrow_len*numpy.max(((X2-X1)**2+(Y2-Y1)**2)**.5)
     aX1=X2-ar_*numpy.cos(ang1)
     aY1=Y2-ar_*numpy.sin(ang1)
     aX2=X2-ar_*numpy.cos(ang2)
     aY2=Y2-ar_*numpy.sin(ang2)

  gist.pldj(X2,Y2,aX1,aY1,color='red')
  gist.pldj(X2,Y2,aX2,aY2,color='red')
  gist.limits()
Exemple #14
0
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)
Exemple #15
0
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)
Exemple #16
0
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
Exemple #17
0
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
Exemple #18
0
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
Exemple #19
0
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
Exemple #20
0
Y2 = y + dy
gist.pldj(X1, Y1, X2, Y2)

arrow_a = numpy.pi / 6.
arrow_len = .5
arrow_scales = False
arrow_scales = True

slo = (Y2 - Y1) / (X2 - X1)
ang = numpy.arctan(slo)
ang1 = ang + arrow_a
ang2 = ang - arrow_a

if arrow_scales:
    ar_ = numpy.sign(X2 - X1) * arrow_len * ((X2 - X1)**2 + (Y2 - Y1)**2)
    aX1 = X2 - ar_ * numpy.cos(ang1)
    aY1 = Y2 - ar_ * numpy.sin(ang1)
    aX2 = X2 - ar_ * numpy.cos(ang2)
    aY2 = Y2 - ar_ * numpy.sin(ang2)
else:
    ar_ = numpy.sign(X2 - X1) * arrow_len * numpy.max(
        ((X2 - X1)**2 + (Y2 - Y1)**2)**.5)
    aX1 = X2 - ar_ * numpy.cos(ang1)
    aY1 = Y2 - ar_ * numpy.sin(ang1)
    aX2 = X2 - ar_ * numpy.cos(ang2)
    aY2 = Y2 - ar_ * numpy.sin(ang2)

gist.pldj(X2, Y2, aX1, aY1, color='red')
gist.pldj(X2, Y2, aX2, aY2, color='red')
gist.limits()