Search code examples
matplotlibjupyter-notebookstatsmodels

displaying statsmodels plot_acf and plot_pacf side by side in a jupyter notebook


can someone show me how to display plot_acf and plot_pacf side by side? I'm struggling with the show=False arguments and matplotlib crazy object model...


Solution

  • You can try using plt.subplot. Here is a short example with a data set from statsmodel to guide you. I hope it is helpful.

    Code

    import pandas as pd
    import matplotlib.pyplot as plt
    import statsmodels.api as sm
    
    dta = sm.datasets.sunspots.load_pandas().data
    dta.index = pd.Index(sm.tsa.datetools.dates_from_range('1700', '2008'))
    del dta["YEAR"]
    #print if you want to visualize
    #print(dta.head())
    
    fig, ax = plt.subplots(1,2,figsize=(10,5))
    sm.graphics.tsa.plot_acf(dta.values.squeeze(), lags=40, ax=ax[0])
    sm.graphics.tsa.plot_pacf(dta.values.squeeze(), lags=40, ax=ax[1])
    plt.show()
    

    Output in Jupyter jupyter_output