示例#1
0
def gray():
    'set the default colormap to gray and apply to current image if any'
    rc('image', cmap='gray')
    im = gci()
    if im is not None:
        im.set_cmap(cm.gray)
        draw_if_interactive()
示例#2
0
def jet():
    'set the default colormap to jet and apply to current image if any'
    rc('image', cmap='jet')
    im = gci()
    if im is not None:
        im.set_cmap(cm.jet)
    draw_if_interactive()
示例#3
0
def clf():
    """
    Clear the current figure
    """
    manager = get_current_fig_manager()
    manager.clf()
    draw_if_interactive()
示例#4
0
def axes(*args, **kwargs):
    """
    Add an axes at positon rect specified by::

    axes() by itself creates a default full subplot(111) window axis

    axes(rect, axisbg='w') where rect=[left, bottom, width, height] in
    normalized (0,1) units.  axisbg is the background color for the
    axis, default white

    axes(h) where h is an axes instance makes h the
    current axis An Axes instance is returned
    """

    nargs = len(args)
    if len(args)==0: return subplot(111, **kwargs)
    if nargs>1:
        error_msg('Only one non keyword arg to axes allowed')
        return
    
    arg = args[0]

    if isinstance(arg, Axes):
        get_current_fig_manager().set_current_axes(arg)
        ret = arg
    else:
        rect = arg
        ret = get_current_fig_manager().add_axes(rect, **kwargs)
    draw_if_interactive()
    return ret
示例#5
0
def xticks(*args, **kwargs):
    """
    Set/Get the xlimits of the current ticklocs, labels

    # return locs, labels where locs is an array of tick locations and
    # labels is an array of tick labels.
    locs, labels = xticks()              

    # set the locations of the xticks
    xticks( arange(6) )

    # set the locations and labels of the xticks
    xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )

    The keyword args, if any, are text properties; see text for more
    information on text properties.  
    """
    ax = gca()
    
    if len(args)==0:
        locs = ax.get_xticks()
        labels = ax.get_xticklabels()
    elif len(args)==1:
        locs = ax.set_xticks(args[0])
        labels = ax.get_xticklabels()        
    elif len(args)==2:
        locs = ax.set_xticks(args[0])
        labels = ax.set_xticklabels(args[1], **kwargs)
    else: raise RuntimeError('Illegal number of arguments to xticks')
    if len(kwargs):
        for l in labels:
            l.update_properties(kwargs)
            
    draw_if_interactive()
    return locs, labels
示例#6
0
def axis(*v):
    """\
Set/Get the axis properties::

    axis()  returns the current axis as a length a length 4 vector

    axis(v) where v = [xmin, xmax, ymin, ymax] sets the min and max of the x
        and y axis limits

    axis('off') turns off the axis lines and labels

    axis('equal') sets the xlim width and ylim height to be to be
        identical.  The longer of the two intervals is chosen
 
"""
    
    if len(v)==1 and is_string_like(v[0]):
        s = v[0]
        if s.lower()=='on': gca().set_axis_on()
        elif s.lower()=='off': gca().set_axis_off()
        elif s.lower()=='equal':
            ax = gca()
            xmin, xmax = ax.get_xlim()
            ymin, ymax = ax.get_ylim()
            
            width = xmax-xmin
            height = ymax-ymin
            # TODO: handle decreasing lim
            
            interval = max([width, height])
            ax.set_xlim((xmin, xmin+interval))
            ax.set_ylim((ymin, ymin+interval))            
            draw_if_interactive()
            
        else:
            error_msg('Unrecognized string %s to axis; try on or off' % s)
        return
    
    try: v[0]
    except IndexError:
        xlim = gca().get_xlim()
        ylim = gca().get_ylim()
        return [xlim[0], xlim[1], ylim[0], ylim[1]]
    
    v = v[0]
    if len(v) != 4:
        error_msg('v must contain [xmin xmax ymin ymax]')
        return 
    gca().set_xlim([v[0], v[1]])
    gca().set_ylim([v[2], v[3]])
    draw_if_interactive()
示例#7
0
def ylim(*args, **kwargs):
    """
    Set/Get the ylimits of the current axes

    ymin, ymax = ylim()   : return the current ylim
    ylim( (ymin, ymax) )  : set the ylim to ymin, ymax
    ylim( ymin, ymax )    : set the ylim to ymin, ymax    
    """
    ax = gca()
    if len(args)==0: return ax.get_ylim()
    elif len(args)==1: lim = ax.set_ylim(args)
    elif len(args)==2: lim = ax.set_ylim((args[0], args[1]))
    else: raise RuntimeError('Illegal number of arguments to ylim')
    draw_if_interactive()
    return lim
示例#8
0
def xlim(*args, **kwargs):
    """
    Set/Get the xlimits of the current axes

    xmin, xmax = xlim()   : return the current xlim
    xlim( (xmin, xmax) )  : set the xlim to xmin, xmax
    xlim( xmin, xmax )    : set the xlim to xmin, xmax    
    """
    ax = gca()
    if len(args)==0: return ax.get_xlim()
    elif len(args)==1: lim = ax.set_xlim(args)
    elif len(args)==2: lim = ax.set_xlim((args[0], args[1]))
    else: raise RuntimeError('Illegal number of arguments to xlim')
    draw_if_interactive()
    return lim
示例#9
0
def title(s, *args, **kwargs):
    """
    Set the title of the current axis to s

    Default font override is:
      override = {
        'fontsize'            : 'medium',
        'verticalalignment'   : 'bottom',
        'horizontalalignment' : 'center'
      }

    See the text docstring for information of how override and the
    optional args work

    """
    l =  gca().set_title(s, *args, **kwargs)
    draw_if_interactive()
    return l
示例#10
0
def figlegend(handles, labels, loc):
    """
    Place a legend in the figure.  Labels are a sequence of
    strings, handles is a sequence of line or patch instances, and
    loc can be a string or an integer specifying the legend
    location

    USAGE: 
      legend( (line1, line2, line3),
              ('label1', 'label2', 'label3'),
              'upper right')

    See help(legend) for information about the location codes

    A matplotlib.legend.Legend instance is returned
    """
    l=  gcf().legend(handles, labels, loc)
    draw_if_interactive()
    return l
示例#11
0
def ylabel(s, *args, **kwargs):
    """
    Set the y axis label of the current axis to s

    Defaults override is

        override = {
           'fontsize'            : 'small',
           'verticalalignment'   : 'center',
           'horizontalalignment' : 'right',
           'rotation'='vertical' : }

    See the text docstring for information of how override and the
    optional args work
    
    """
    l = gca().set_ylabel(s, *args, **kwargs)
    draw_if_interactive()
    return l
示例#12
0
def clim(vmin=None, vmax=None):
    """
    Set the color limits of the current image

    To apply clim to all axes images do

    clim(0, 0.5)

    If either vmin or vmax is None, the image min/max respectively
    will be used for color scaling.

    If you want to set the clim of multiple images,
    use, for example for im in gca().get_images(): im.set_clim(0,
    0.05)
    
    """  
    im = gci._current
    if im is None:
        error_msg('You must first define an image, eg with imshow')
        return
    im.set_clim(vmin, vmax)
    draw_if_interactive()
示例#13
0
def rcdefaults():
    matplotlib.rcdefaults()
    draw_if_interactive()
示例#14
0
def rc(*args, **kwargs):
    matplotlib.rc(*args, **kwargs)
    draw_if_interactive()
示例#15
0
                             argdefs)

    print f.func_defaults
    newf.__doc__ = f.__doc__
    return newf

def _wrap_axfunc(name):
    def wrapper(*args, **kwargs):
        try:
            func = getattr(gca(), name)
            ret =  func(*args, **kwargs)
        except ValueError, msg:
            msg = raise_msg_to_str(msg)
            error_msg(msg)
        else:
            draw_if_interactive()
            return ret
    wrapper.__doc__ = getattr(Axes, name).__doc__
    #wrapper.__name__ = name
    return changed_name_function(wrapper, name)



# these methods are all simple wrappers of Axes methods by the same
# name.  We'll autogenerate these to avoid some of the boilerplate
# using the fmt string above.
_methods = (
    'axhline',
    'axhspan',
    'axvline',
    'axvspan',