我绘制了4个不同国家的自相关图和部分自相关图。
我的数据都集中在一个数据帧中。
我非常方便/简明地用图表表示它是这样的
from statsmodels.graphics.tsaplots import plot_acf
countries = ['Germany', 'Spain', 'Italy', 'US']
figs = df.query("Country_Region in @countries")\
.groupby("Country_Region")['ConfirmedCases'].apply(plot_acf)
_ = [fig.suptitle(name) for fig, name in zip(figs, countries)]from statsmodels.graphics.tsaplots import plot_pacf
countries = ['Germany', 'Spain', 'Italy', 'US']
figs = df.query("Country_Region in @countries")\
.groupby("Country_Region")['ConfirmedCases'].apply(plot_pacf)
_ = [fig.suptitle(name) for fig, name in zip(figs, countries)]作为两个单独的数字列表,这在笔记本中看起来不是很好…
我知道subplots是用来排序一个图形的轴,但我有多个图形,我想安排…
我想我必须重新实现我正在做的事情,让它看起来更漂亮,但我想看看是否有一种方便的方法来组织图形,或者我需要写一些更有表现力的东西来得到我想要的东西。
一个好的布局应该是这样的
plot_acf(germany) plot_pacf(germany)
plot_pacf(spain) plot_pacf(spain)
plot_pacf(italy) plot_pacf(italy)
plot_pacf(us) plot_pacf(us)发布于 2020-11-03 02:39:17
这就是我最终要做的
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.graphics.tsaplots import plot_pacf
fig, axes = plt.subplots(4,2, figsize=(20,10))
for i, (country,data) in enumerate(df.query("Country_Region in ['Germany', 'Spain', 'Italy', 'US']").groupby("Country_Region")['ConfirmedCases']):
plot_acf(data, ax=axes[i,0], title=country+" Autocorrelation")
plot_pacf(data, ax=axes[i,1], title=country+" Autocorrelation")
fig.tight_layout()(在暗模式下看起来不是很好,但如果是在浅色背景下就足够好了)

https://stackoverflow.com/questions/64651040
复制相似问题