Example #1
0
def figure(n=None,style=os.path.join(_user_path,"currstyle.gs"), color=-2, frame=0, labelsize=14, labelfont='helvetica',aspect=1.618,land=0):
    global _figures
    if (aspect < 0.1) or (aspect > 10):
        aspect = 1.618
    if isinstance(color, types.StringType):
        color = _colornum[color]
    fid = open(style,'w')
    syst = write_style.getsys(color=color,frame=frame,
                             labelsize=labelsize,font=labelfont)
    if land:
        cntr = (5.5*inches,4.25*inches)  # horizontal, vertical
    else:
        cntr = (4.25*inches,5.5*inches)
    height = 4.25*inches
    width = aspect*height
    syst['viewport'] = [cntr[0]-width/2.0,cntr[0]+width/2.0,cntr[1]-height/2.0,cntr[1]+height/2.0]
    fid.write(write_style.style2string(syst,landscape=land))
    fid.close()
    if n is None:
        winnum = gist.window(style=style,width=int(width*1.25/inches*_dpi),height=int(height*1.4/inches*_dpi))
        if winnum < 0:
            gist.window(style=style,width=int(width*1.25/inches*_dpi),height=int(height*1.4/inches*_dpi))
    else:
        gist.window(n,style=style,width=int(width*1.25/inches*_dpi),height=int(height*1.4/inches*_dpi))
        _current_style = style
    return
Example #2
0
def figure(n=None,style=os.path.join(_user_path,"currstyle.gs"), color=-2, frame=0, labelsize=14, labelfont='helvetica',aspect=1.618,land=0):
    global _figures
    if (aspect < 0.1) or (aspect > 10):
        aspect = 1.618
    if isinstance(color, types.StringType):
        color = _colornum[color]
    fid = open(style,'w')
    syst = write_style.getsys(color=color,frame=frame,
                             labelsize=labelsize,font=labelfont)
    if land:
        cntr = (5.5*inches,4.25*inches)  # horizontal, vertical
    else:
        cntr = (4.25*inches,5.5*inches)
    height = 4.25*inches
    width = aspect*height
    syst['viewport'] = [cntr[0]-width/2.0,cntr[0]+width/2.0,cntr[1]-height/2.0,cntr[1]+height/2.0]
    fid.write(write_style.style2string(syst,landscape=land))
    fid.close()
    if n is None:
        winnum = gist.window(style=style,width=int(width*1.25/inches*_dpi),height=int(height*1.4/inches*_dpi))
        if winnum < 0:
            gist.window(style=style,width=int(width*1.25/inches*_dpi),height=int(height*1.4/inches*_dpi))
    else:
        gist.window(n,style=style,width=int(width*1.25/inches*_dpi),height=int(height*1.4/inches*_dpi))
        _current_style = style
    return
Example #3
0
def imagesc(z,cmin=None,cmax=None,xryr=None,_style='default', palette=None,
            color='black',colormap=None):
    """Plot an image on axes.

    z -- The data
    cmin -- Value to map to lowest color in palette (min(z) if None)
    cmax -- Value to map to highest color in palette (max(z) if None)
    xryr -- (xmin, ymin, xmax, ymax) coordinates to print
            (0, 0, z.shape[1], z.shape[0]) if None
    _style -- A 'style-sheet' to use if desired (a default one will be used
              if 'default').  If None, then no style will be imposed.
    palette -- A string for a palette previously saved in a file (see write_palette)
               or an array specifying the red-green-blue values (2-d array N x 3) or
               gray-scale values (2-d array N x 1 or 1-d array).
    color -- The color to use for the axes.
    """
    if xryr is None:
        xryr = (0,0,z.shape[1],z.shape[0])
    try:
        _style = None
        saveval = gist.plsys(2)
        gist.plsys(saveval)
    except:
        _style = 'default'
        if not _hold:
            gist.fma()
        gist.animate(0)

    if _style is not None:
        if _style == "default":
            _style=os.path.join(_user_path,'image.gs')
            system = write_style.getsys(hticpos='below',vticpos='left',frame=1,
                                        color=color)
            fid = open(_style,'w')
            fid.write(write_style.style2string(system))
            fid.close()
        gist.window(style=_style)
        _current_style=_style
    if cmax is None:
        cmax = max(ravel(z))
    if cmin is None:
        cmin = min(ravel(z))
    cmax = float(cmax)
    cmin = float(cmin)
    byteimage = gist.bytscl(z,cmin=cmin,cmax=cmax)
    if (colormap is not None): palette=colormap
    change_palette(palette)
    gist.pli(byteimage,xryr[0],xryr[1],xryr[2],xryr[3])
    return
Example #4
0
def imagesc(z,cmin=None,cmax=None,xryr=None,_style='default', palette=None,
            color='black',colormap=None):
    """Plot an image on axes.

    z -- The data
    cmin -- Value to map to lowest color in palette (min(z) if None)
    cmax -- Value to map to highest color in palette (max(z) if None)
    xryr -- (xmin, ymin, xmax, ymax) coordinates to print
            (0, 0, z.shape[1], z.shape[0]) if None
    _style -- A 'style-sheet' to use if desired (a default one will be used
              if 'default').  If None, then no style will be imposed.
    palette -- A string for a palette previously saved in a file (see write_palette)
               or an array specifying the red-green-blue values (2-d array N x 3) or
               gray-scale values (2-d array N x 1 or 1-d array).
    color -- The color to use for the axes.
    """
    if xryr is None:
        xryr = (0,0,z.shape[1],z.shape[0])
    try:
        _style = None
        saveval = gist.plsys(2)
        gist.plsys(saveval)
    except:
        _style = 'default'
        if not _hold:
            gist.fma()
        gist.animate(0)

    if _style is not None:
        if _style == "default":
            _style=os.path.join(_user_path,'image.gs')
            system = write_style.getsys(hticpos='below',vticpos='left',frame=1,
                                        color=color)
            fid = open(_style,'w')
            fid.write(write_style.style2string(system))
            fid.close()
        gist.window(style=_style)
        _current_style=_style
    if cmax is None:
        cmax = max(ravel(z))
    if cmin is None:
        cmin = min(ravel(z))
    cmax = float(cmax)
    cmin = float(cmin)
    byteimage = gist.bytscl(z,cmin=cmin,cmax=cmax)
    if (colormap is not None): palette=colormap
    change_palette(palette)
    gist.pli(byteimage,xryr[0],xryr[1],xryr[2],xryr[3])
    return
Example #5
0
def imagesc_cb(z,cmin=None,cmax=None,xryr=None,_style='default',
               zlabel=None,font='helvetica',fontsize=16,color='black',
               palette=None):
    """Plot an image on axes with a colorbar on the side.

    z -- The data
    cmin -- Value to map to lowest color in palette (min(z) if None)
    cmax -- Value to map to highest color in palette (max(z) if None)
    xryr -- (xmin, ymin, xmax, ymax) coordinates to print
            (0, 0, z.shape[1], z.shape[0]) if None
    _style -- A 'style-sheet' to use if desired (a default one will be used
              if 'default').  If None, then no style will be imposed.
    palette -- A string for a palette previously saved in a file (see write_palette)
               or an array specifying the red-green-blue values (2-d array N x 3) or
               gray-scale values (2-d array N x 1 or 1-d array).
    zlabel -- The label to attach to the colorbar (font, fontsize, and color
              match this).
    color -- The color to use for the ticks and frame.
    """
    if xryr is None:
        xryr = (0,0,z.shape[1],z.shape[0])

    if not _hold:
        gist.fma()
    gist.animate(0)
    if _style is not None:
        if _style == 'default':
            _style=os.path.join(_user_path,"colorbar.gs")
            system = write_style.getsys(hticpos='below',vticpos='left',frame=1,color=color)
            fid = open(_style,'w')
            fid.write(write_style.style2string(system))
            fid.close()
        gist.window(style=_style)
        _current_style=_style
    if cmax is None:
        cmax = max(ravel(z))
    if cmin is None:
        cmin = min(ravel(z))
    cmax = float(cmax)
    cmin = float(cmin)

    change_palette(palette)

    byteimage = gist.bytscl(z,cmin=cmin,cmax=cmax)
    gist.pli(byteimage,xryr[0],xryr[1],xryr[2],xryr[3])
    colorbar.color_bar(cmin,cmax,ncol=240,zlabel=zlabel,font=font,fontsize=fontsize,color=color)
Example #6
0
def imagesc_cb(z,cmin=None,cmax=None,xryr=None,_style='default',
               zlabel=None,font='helvetica',fontsize=16,color='black',
               palette=None):
    """Plot an image on axes with a colorbar on the side.

    z -- The data
    cmin -- Value to map to lowest color in palette (min(z) if None)
    cmax -- Value to map to highest color in palette (max(z) if None)
    xryr -- (xmin, ymin, xmax, ymax) coordinates to print
            (0, 0, z.shape[1], z.shape[0]) if None
    _style -- A 'style-sheet' to use if desired (a default one will be used
              if 'default').  If None, then no style will be imposed.
    palette -- A string for a palette previously saved in a file (see write_palette)
               or an array specifying the red-green-blue values (2-d array N x 3) or
               gray-scale values (2-d array N x 1 or 1-d array).
    zlabel -- The label to attach to the colorbar (font, fontsize, and color
              match this).
    color -- The color to use for the ticks and frame.
    """
    if xryr is None:
        xryr = (0,0,z.shape[1],z.shape[0])

    if not _hold:
        gist.fma()
    gist.animate(0)
    if _style is not None:
        if _style == 'default':
            _style=os.path.join(_user_path,"colorbar.gs")
            system = write_style.getsys(hticpos='below',vticpos='left',frame=1,color=color)
            fid = open(_style,'w')
            fid.write(write_style.style2string(system))
            fid.close()
        gist.window(style=_style)
        _current_style=_style
    if cmax is None:
        cmax = max(ravel(z))
    if cmin is None:
        cmin = min(ravel(z))
    cmax = float(cmax)
    cmin = float(cmin)

    change_palette(palette)

    byteimage = gist.bytscl(z,cmin=cmin,cmax=cmax)
    gist.pli(byteimage,xryr[0],xryr[1],xryr[2],xryr[3])
    colorbar.color_bar(cmin,cmax,ncol=240,zlabel=zlabel,font=font,fontsize=fontsize,color=color)
Example #7
0
def subplot(Numy,Numx,win=0,pw=None,ph=None,hsep=100,vsep=100,color='black',frame=0,fontsize=8,font=None,ticks=1,land=0):
    # Use gist.plsys to change coordinate systems

    # all inputs (except fontsize) given as pixels, gist wants
    #  things in normalized device
    #  coordinate.  Window is brought up with center of window at
    #  center of 8.5 x 11 inch page: in landscape mode (5.25, 4.25)
    #  or at position (4.25,6.75) for portrait mode
    msg = 1
    if pw is None:
        pw = Numx*300
        msg = 0
    if ph is None:
        ph = Numy*300
        msg = 0
    if land:
        maxwidth=min(_maxwidth,11*_dpi)
        maxheight=min(_maxheight,8.5*_dpi)
    else:
        maxwidth=min(_maxwidth,8.5*_dpi)
        maxheight=min(_maxheight,11*_dpi)

    printit = 0
    if ph > maxheight:
        ph = maxheight
        printit = 1
    if pw > maxwidth:
        pw = maxwidth
        printit = 1

    if _dpi != 100:
        fontsize = 12
    conv = inches *1.0 / _dpi  # multiply by this factor to convert pixels to
                              # NDC

    if printit and msg:
        message = "Warning: Requested height and width too large.\n"
        message +="Changing to %d x %d" % (pw,ph)
        print message

    # Now we've got a suitable height and width

    if land:
        cntr = array([5.5,4.25])*_dpi  # landscape
    else:
        if sys.platform == 'win32':
            cntr = array([4.25,6.75])*_dpi  # portrait
        else:
            cntr = array([4.25,5.5])*_dpi

    Yspace = ph/float(Numy)*conv
    Xspace = pw/float(Numx)*conv

    hsep = hsep * conv
    vsep = vsep * conv
    ytop = (cntr[1]+ph/2.0)*conv
    xleft = (cntr[0]-pw/2.0)*conv

    if type(color) is types.StringType:
        color = _colornum[color]
    systems=[]
    ind = -1
    for nY in range(Numy):
        ystart = ytop - (nY+1)*Yspace
        for nX in range(Numx):
            xstart = xleft + nX*Xspace
            systems.append({})
            systems[-1]['viewport'] = [xstart+hsep/2.0,xstart+Xspace-hsep/2.0,ystart+vsep/2.0,ystart+Yspace-vsep/2.0]
            if font is not None or fontsize is not None:
                _chng_font(systems[-1],font,fontsize)
            if color != -3 or frame != 0:
                _add_color(systems[-1],color,frame=frame)
            if ticks != 1:
                _remove_ticks(systems[-1])
    _current_style=os.path.join(_user_path,"subplot%s.gs" % win)
    fid = open(_current_style,'w')
    fid.write(write_style.style2string(systems,landscape=land))
    fid.close()
    gist.winkill(win)
    gist.window(win,style=_current_style,width=int(pw),height=int(ph))
Example #8
0
def subplot(Numy,Numx,win=0,pw=None,ph=None,hsep=100,vsep=100,color='black',frame=0,fontsize=8,font=None,ticks=1,land=1,wait=0,**kwd):
    # Use gist.plsys to change coordinate systems

    # all inputs (except fontsize) given as pixels, gist wants
    #  things in normalized device
    #  coordinate.  Window is brought up with center of window at
    #  center of 8.5 x 11 inch page: in landscape mode (5.25, 4.25)
    #  or at position (4.25,6.75) for portrait mode
    
    # kwd for window (... , parent=None,xpos=None,ypos=None)
    msg = 1
    if pw is None:
        pw = Numx*300
        msg = 0
    if ph is None:
        ph = Numy*300
        msg = 0
    if land:
        maxwidth=min(_maxwidth,11*_dpi)
        maxheight=min(_maxheight,8.5*_dpi)
    else:
        maxwidth=min(_maxwidth,8.5*_dpi)
        maxheight=min(_maxheight,11*_dpi)

    printit = 0
    if ph > maxheight:
        ph = maxheight
        printit = 1
    if pw > maxwidth:
        pw = maxwidth
        printit = 1

    if _dpi != 100:
        fontsize = 12
    conv = inches *1.0 / _dpi  # multiply by this factor to convert pixels to
                              # NDC

    if printit and msg:
        message = "Warning: Requested height and width too large.\n"
        message +="Changing to %d x %d" % (pw,ph)
        print message

    # Now we've got a suitable height and width

    if land:
        cntr = array([5.5,4.25])*_dpi  # landscape
    else:
        if sys.platform == 'win32':
            cntr = array([4.25,6.75])*_dpi  # portrait
        else:
            cntr = array([4.25,5.5])*_dpi

    Yspace = ph/float(Numy)*conv
    Xspace = pw/float(Numx)*conv

    hsep = hsep * conv
    vsep = vsep * conv
    ytop = (cntr[1]+ph/2.0)*conv
    xleft = (cntr[0]-pw/2.0)*conv

    if type(color) is types.StringType:
        color = _colornum[color]
    systems=[]
    ind = -1
    for nY in range(Numy):
        ystart = ytop - (nY+1)*Yspace
        for nX in range(Numx):
            xstart = xleft + nX*Xspace
            systems.append({})
            systems[-1]['viewport'] = [xstart+hsep/2.0,xstart+Xspace-hsep/2.0,ystart+vsep/2.0,ystart+Yspace-vsep/2.0]
            if font is not None or fontsize is not None:
                _chng_font(systems[-1],font,fontsize)
            if color != -3 or frame != 0:
                _add_color(systems[-1],color,frame=frame)
            if ticks != 1:
                _remove_ticks(systems[-1])
    _current_style=os.path.join(_user_path,"subplot%s.gs" % win)
    fid = open(_current_style,'w')
    fid.write(write_style.style2string(systems,landscape=land))
    fid.close()
    gist.winkill(win)
    gist.window(win,style=_current_style,width=int(pw),height=int(ph),wait=wait,**kwd)