【问题标题】:How do I use the detrending function for matplotlib.pyplot.acorr?如何对 matplotlib.pyplot.acorr 使用去趋势函数?
【发布时间】:2019-07-08 05:34:02
【问题描述】:

我是 Python 初学者。我试图通过在 matplotlib 中使用 acorr 在运行自相关分析之前消除时间序列的趋势。但是我无法理解语法。

Matplotlib 的网站 (https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.acorr.html) 描述了如何将去趋势与 acorr 函数一起使用:“x 被 detrend 可调用对象去趋势。这必须是一个函数 x = detrend(x) 接受并返回一个 numpy.array。”我一定是看错了,因为我使用的代码不起作用。

尝试失败:

plt.acorr(values, detrend=True)
plt.acorr(values, detrend="linear")
plt.acorr(values=detrend(values))

如您所见,一些关于语法或 matplotlib 的基本事实让我无法理解。请帮忙。

【问题讨论】:

    标签: python matplotlib autocorrelation


    【解决方案1】:

    matplotlib.mlab 中,您可以找到可用于去趋势的函数。一个例子:

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib import mlab
    
    wn = np.random.normal(size=10**3)
    
    plt.figure()
    plt.acorr(np.abs(wn), maxlags=200, detrend=mlab.detrend_none) #default detrend
    
    plt.figure()
    plt.acorr(np.abs(wn), maxlags=200, detrend=mlab.detrend) #subtract sample mean
    

    【讨论】:

      猜你喜欢
      • 2018-12-20
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多