I am having trouble plotting AR and MA models for time series of weather. For example:
from statsmodels.tsa.arima_process import arma_generate_sample
def gen_ar2(alpha1,alpha2,size):
ar = [1,-alpha1,-alpha2]
ma = [1]
return arma_generate_sample(ar,ma,size)
Hence, if I want to plot lets say x(t) = 0.75 x(t-1) - 0.125 x(t-2) + w(t), where w(t) is Normal with mean 0 and variance 1 (lets say)...plotting this generally plots twice on ipython notebook, i.e
sm.graphics.tsa.plot_acf(gen_ar2(0.75,-0.125,size=5000),lags=40)
this creates two plots for me instead of just one. how do i stop ipython from doing this?
thanks
You see two plots because the plot_acf
function creates the plot and returns the figure object. In a "normal" python IDE or script this would not result in two images, but IPython with its inline backend displays a figure once it is created in a cell. Moreover, the returned figure is displayed as well. Later is indicated by the OUT[x] prompt.
To get a single image, simply save the output to some variable (to prevent its display) like
_ = sm.graphics.tsa.plot_acf(gen_ar2(0.75,-0.125,size=5000),lags=40)
or suppress the output like (note the ;
!)
sm.graphics.tsa.plot_acf(gen_ar2(0.75,-0.125,size=5000),lags=40);
In both ways you only get the displayed data and not the returned data displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With