I'm starting out with Jupiter to analyze some sales data. It's working, but every time I plot a chart, the chart shows up twice. The first two charts in my notebook are plotted from within a class, and for these it doesn't happen (note, Model
here refers to a model of a product, not a predictive model):
class Model:
...
def plot(self):
self.weekly_sales.plot() # a pandas Series
self.decomposed.plot() # result of seasonal_decompose on the weekly_sales
my_model = Model('model name', sales)
%matplotlib inline
my_model.plot()
All looks good. But then I execute the next three lines:
my_model.weekly_sales.autocorr()
from stats models.graphics.tsaplots import plot_acf
plot_acf(my_model.weekly_sales)
Every subsequent plot appears twice, including an ARMA
model's fit
and plot_pacf
.
It's not a big deal. I'm getting the information I need, but it is a bit annoying. Why is it doing this?
Update: Going further along in the analysis, I printed a DataFrame
in the same Jupyter cell as the ACF and PACF outputs, and it printed the frame and showed both the charts only once. I went back to the other cells with duplicate chart outputs, added a print()
at the end of each one, and now each one appears only once.
The issue/question is arround for quite a while already. See issue 1265. So far "This seems to be caused by the plot_acf function both plotting the graph AND returning the results which then causes IPython Notebook to plot the results again."
For the issue there are several ways to overcome the double plotting.
1) as you mentioned add print()
after the acf_plot
2) assign the output e.g. output_plt = plot_acf(my_model.weekly_sales)
3) add a semicolon after the row plot_acf(my_model.weekly_sales);
4) If matplotlib is imported anyway execute a plt.show()
in the same cell
5) Changing the %matplotlib
properties. This is not recommended as it has effects on other plottings
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