【发布时间】:2020-06-25 08:10:05
【问题描述】:
我想修改 ACF 和 PACF 图的 X 轴刻度,即我希望每 2 和 4 个单位(次要和主要刻度)后有一个刻度,而不是默认的 20 个单位。我正在尝试以下代码:
from statsmodels.graphics.tsaplots import plot_acf,plot_pacf
rcParams['figure.figsize']=20,10
ax = plt.subplot(211)
plot_acf(ts_log_diff)
ax.xaxis.set_major_locator(plt.MultipleLocator=4)
ax.xaxis.set_minor_locator(plt.MultipleLocator=2)
plt.subplot(212)
plot_pacf(ts_log_diff, ax=plt.gca())
plt.show()
我得到的错误信息是:
File "<ipython-input-99-bfa377e377fd>", line 5
ax.xaxis.set_major_locator(plt.MultipleLocator=4)
^
SyntaxError: keyword can't be an expression
我在 pd.plotting.autocorrelation_plot 中使用了类似的语法,它正在工作:
plotacf= pd.plotting.autocorrelation_plot(ts_log_diff)
plotacf.xaxis.set_major_locator(plt.MultipleLocator(2))
plotacf.xaxis.set_minor_locator(plt.MultipleLocator( 4))
【问题讨论】:
-
我不确定其他代码,但是在Python中,你不能在关键字参数中使用点 - (plt.MultipleLocator=4)`你为什么不使用下面的?ax.xaxis .set_major_locator(plt.MultipleLocator(4))
-
谢谢伙计。我的错。那是语法的问题。是的,这种语法有效:
标签: python matplotlib time-series advanced-custom-fields statsmodels