|
6 | 6 | transpose, log, log10, Float, Float32, ravel, zeros,\
|
7 | 7 | Int16, Int32, Int, Float64, ceil, indices, \
|
8 | 8 | shape, which, where, sqrt, asum, compress, maximum, minimum, \
|
9 |
| - typecode, concatenate, newaxis, reshape, resize, repeat |
| 9 | + typecode, concatenate, newaxis, reshape, resize, repeat, cross_correlate, nonzero |
10 | 10 |
|
11 | 11 | import numerix.ma as ma
|
12 | 12 |
|
@@ -2208,7 +2208,7 @@ def vlines(self, x, ymin, ymax, fmt='k-', **kwargs):
|
2208 | 2208 | return lines
|
2209 | 2209 | vlines.__doc__ = dedent(vlines.__doc__) % artist.kwdocd
|
2210 | 2210 |
|
2211 |
| - |
| 2211 | + |
2212 | 2212 | #### Basic plotting
|
2213 | 2213 | def plot(self, *args, **kwargs):
|
2214 | 2214 | """
|
@@ -2366,6 +2366,7 @@ def plot_date(self, x, y, fmt='bo', tz=None, xdate=True, ydate=False,
|
2366 | 2366 | return ret
|
2367 | 2367 | plot_date.__doc__ = dedent(plot_date.__doc__) % artist.kwdocd
|
2368 | 2368 |
|
| 2369 | + |
2369 | 2370 | def loglog(self, *args, **kwargs):
|
2370 | 2371 | """
|
2371 | 2372 | LOGLOG(*args, **kwargs)
|
@@ -2482,6 +2483,45 @@ def semilogy(self, *args, **kwargs):
|
2482 | 2483 | return l
|
2483 | 2484 | semilogy.__doc__ = dedent(semilogy.__doc__) % artist.kwdocd
|
2484 | 2485 |
|
| 2486 | + def xcorr(self, x, y, normed=False, detrend=detrend_none, **kwargs): |
| 2487 | + """ |
| 2488 | + Plot the cross correlation between x and y. If normed=True, |
| 2489 | + normalize the data but the cross correlation at 0-th lag. x |
| 2490 | + and y are deterned by the detrend callable (default no |
| 2491 | + normalization. x and y must be equal length |
| 2492 | +
|
| 2493 | + data are plotted as plot(lags, c, **kwargs) |
| 2494 | +
|
| 2495 | + return value is lags, c, line where lags are a length |
| 2496 | + 2*len(x)+1 lag vector, c is the 2*len(x)+1 cross correlation |
| 2497 | + vector, and line is a Line2D instance returned by plot. The |
| 2498 | + default linestyle is None and the default marker is 'o', |
| 2499 | + though these can be overridden with keyword args. The cross |
| 2500 | + correlation is performed with numerix cross_correlate with |
| 2501 | + mode=2. |
| 2502 | +
|
| 2503 | + The valid kwargs are Line2D properties: |
| 2504 | + %(Line2D)s |
| 2505 | + """ |
| 2506 | + kwargs = kwargs.copy() |
| 2507 | + kwargs.setdefault('marker', 'o') |
| 2508 | + kwargs.setdefault('linestyle', 'None') |
| 2509 | + |
| 2510 | + Nx = len(x) |
| 2511 | + assert(Nx==len(y)) |
| 2512 | + x = detrend(asarray(x)) |
| 2513 | + y = detrend(asarray(y)) |
| 2514 | + |
| 2515 | + c = cross_correlate(x, y, mode=2) |
| 2516 | + |
| 2517 | + if normed: c/=c[Nx-1] |
| 2518 | + |
| 2519 | + |
| 2520 | + lags = arange(-Nx+1,Nx) |
| 2521 | + line, = self.plot(lags, c, **kwargs) |
| 2522 | + return lags, c, line |
| 2523 | + xcorr.__doc__ = dedent(xcorr.__doc__) % artist.kwdocd |
| 2524 | + |
2485 | 2525 | def legend(self, *args, **kwargs):
|
2486 | 2526 | """
|
2487 | 2527 | LEGEND(*args, **kwargs)
|
|
0 commit comments