在 jupyter 笔记本中并排显示 statsmodels plot_acf 和 plot_pacf

iha*_*nny 2 matplotlib statsmodels jupyter-notebook

有人可以告诉我如何显示plot_acfplot_pacf并排?我在show=False争论和 matplotlib 疯狂的对象模型中挣扎......

Qua*_*ats 5

您可以尝试使用plt.subplot. 这是一个简短的示例,其中包含来自 statsmodel 的数据集,可以为您提供指导。我希望它有帮助。

代码

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()
Run Code Online (Sandbox Code Playgroud)

Jupyter 中的输出 jupyter_output