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

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

yuchenwang1191 回答:在jupyter笔记本中并排显示statsmodels plot_acf和plot_pacf

您可以尝试使用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(),ax=ax[1])
plt.show()

Jupyter中的输出 jupyter_output

本文链接:https://www.f2er.com/3125725.html

大家都在问