Thank you verymuch Hobson,
However I think I did not understand the suggestion by you fully( pardon my ignorance). I use the below test code from matplotlib site. How does one make a call to get lags and correlation corresponding to the x and y values in the plot. a Print command of
In [23]: print ax1.xcorr
<bound method AxesSubplot.xcorr of <matplotlib.axes.AxesSubplot object at 0x44c1410>>
results as above. Is it possible to assign the xcorr,lags=ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2) ? with a different syntax? I get below error when I try the above .
In [27]: xcorr,lags=ax1.xcorr(x, y, usevlines=True,
maxlags=50, normed=True, lw=2)
···
ValueError Traceback (most recent call last)
/home/sjo/work/PY_WORK/stats/ in ()
----> 1 xcorr,lags=ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
ValueError: too many values to unpack
import matplotlib.pyplot as plt
import numpy as np
x,y = np.random.randn(2,100)
fig = plt.figure()
ax1 =
fig.add_subplot(211)
ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
ax1.grid(True)
ax1.axhline(0, color=‘black’, lw=2)
ax2 = fig.add_subplot(212, sharex=ax1)
ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
ax2.grid(True)
ax2.axhline(0, color=‘black’, lw=2)
plt.show()
From: Paul Hobson <pmhobson@…287…>
To: Sudheer Joseph <sudheer.joseph@…9…>
Cc:
“matplotlib-users@lists.sourceforge.net” <matplotlib-users@…1753…forge.net>
Sent: Thursday, 7 February 2013 10:31 PM
Subject: Re: [Matplotlib-users] cross correlation
On Thu, Feb 7, 2013 at 3:24 AM, Sudheer Joseph <sudheer.joseph@…9…> wrote:
Dear Users,
I am relatively new to Matplotlib. I wanted to find cross correlation between 2 time series for my research and was looking at options available with python and found [http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr) . However I
wanted to save the results in a netcdf file for further use. ie the correlation, lags and significance if possible. Is there a way to get the corr and lags from the axis.xcorr ?? any help in this matter will be greatly appreciated.
Sudheer
Sudheer,
A call to axes.xcorr returns the lags, correlation (from np.correlate) and the line artists on the figure.
In IPython, doing “plt.xcorr??” should provide sufficient information. It’s a pretty simple method.
-paul