Hi,

I was looking at the autocorrelation of a time series recently and it was
useful to scale the x-axis (i.e. multiply lags by the timestep of my actual
data). It's a trivial change, but it might be useful for others. Here's a
standalone version of axes.acorr:

def scaledacorr(x, stepsize=1, normed=False, detrend=mlab.detrend_none,
                usevlines=False, maxlags=None, **kwargs):

    import numpy as np
    x = detrend(np.asarray(x))
    Nx = len(x)
    y = x

    c = np.correlate(x, y, mode=2)

    if normed: c/= np.sqrt(np.dot(x,x) * np.dot(y,y))

    if maxlags is None: maxlags = Nx - 1

    if maxlags >= Nx or maxlags < 1:
        raise ValueError('maglags must be None or strictly '
                         'positive < %d'%Nx)

    lags = np.arange(-maxlags,maxlags+1) * stepsize
    c = c[Nx-1-maxlags:Nx+maxlags]

    if usevlines:
        a = vlines(lags, [0], c, **kwargs)
        b = axhline(**kwargs)
    else:

        kwargs.setdefault('marker', 'o')
        kwargs.setdefault('linestyle', 'None')
        a, = plot(lags, c, **kwargs)
        b = None

    return lags, c, a, b


-- 
Michael Lerner, Ph.D.
IRTA Postdoctoral Fellow
Laboratory of Computational Biology NIH/NHLBI
5635 Fishers Lane, Room T909, MSC 9314
Rockville, MD 20852 (UPS/FedEx/Reality)
Bethesda MD 20892-9314 (USPS)
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to