我想修改ACF&;的X轴刻度;PACF图,即我希望在每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.autocorrelations_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))
为了结束这个问题,我从评论转到了回答
代码的问题是使用了带点的关键字参数,这是无效的语法。但是您根本不需要使用关键字参数。相反,您需要调用以下命令:
ax.xaxis.set_major_locator(plt.MultipleLocator(4))
我建议检查更多关于关键字参数的信息,以便您理解语法
关键字参数示例:
例如,您有一个函数:
您可以调用
quadratic(31, 93, 62)
或直接使用args名称调用quadratic(a=31, b=93, c=62)
资料来源:https://treyhunner.com/2018/04/keyword-arguments-in-python/
相关问题 更多 >
编程相关推荐