【问题标题】:Statsmodels.api.tsa.seasonal_decompose plot figsizeStatsmodels.api.tsa.seasonal_decompose plot figsize
【发布时间】:2022-01-19 10:41:38
【问题描述】:

我正在使用statsmodels.api.tsa.seasonal_decompose 对时间序列进行一些季节性分析。

我是用

设置的
decomp_viz = sm.tsa.seasonal_decompose(df_ts['NetConsumption'], period=48*180)

然后尝试使用可视化它

decomp_viz.plot()

输出很小所以我尝试使用标准的matplotlib命令

decomp_viz.plot(figsize=(20,20))

但是,这得到了警告:

TypeError: plot() got an unexpected keyword argument 'figsize'

文档说 matplotlib.figure.Figure 是从 DecomposeResult.plot 返回的,所以我不确定为什么会发生此错误。

我的statsmodels 版本是0.13.1,我知道该文档是针对0.14.0 的,但conda 说该版本不存在,我无法更新。

任何想法将不胜感激。

【问题讨论】:

    标签: python-3.x statsmodels


    【解决方案1】:

    DecomposeResult.plot 不传递关键字参数。您可以在创建后更改图形大小:

    import statsmodels.api as sm
    import numpy as np
    import matplotlib.pyplot as plt
    
    PERIOD = 48*180
    g = np.random.default_rng(20211225)
    y = np.cos(2 * np.pi * np.linspace(0, 10.0, 10*PERIOD))
    y += g.standard_normal(y.shape)
    
    decomp_viz = sm.tsa.seasonal_decompose(y, period=PERIOD)
    fig = decomp_viz.plot()
    fig.set_size_inches((16, 9))
    # Tight layout to realign things
    fig.tight_layout()
    plt.show()
    

    或者,您可以通过更改 MPL rc 来做同样的事情。

    import statsmodels.api as sm
    import numpy as np
    import matplotlib.pyplot as plt
    # Change default figsize
    plt.rc("figure",figsize=(20,20))
    
    PERIOD = 48*180
    g = np.random.default_rng(20211225)
    y = np.cos(2 * np.pi * np.linspace(0, 10.0, 10*PERIOD))
    y += g.standard_normal(y.shape)
    
    decomp_viz = sm.tsa.seasonal_decompose(y, period=PERIOD)
    decomp_viz.plot()
    plt.show()
    

    产生(裁剪为我的屏幕太大)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多