statsmodels: Duplicate Plots, notebook displays twice

I am starting IPython Notebook with ipython notebook --pylab=inline and then plotting using plot_acf. I am currently getting the resulting plots duplicated:

image

What am I doing wrong here?

Standard pandas plotting using returns_sq.plot() works fine (only one resulting plot).

About this issue

  • Original URL
  • State: open
  • Created 11 years ago
  • Reactions: 16
  • Comments: 15 (8 by maintainers)

Most upvoted comments

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. If instead I assign the results to a variable, then I get only a single plot: x = plot_pacf(...)

For anyone looking for a quick hack around this, it is possible to suppress the returned output from being evaluated by Jupyter simply by adding a semi-colon after the line: plot_acf(data); Not an ideal solution, but easier than most other hacks.

just another data point: This occurred for me when I set %matplotlib inline in one part of the notebook, then used %matplotlib later. I was able to get rid of the duplicate only by entering %matplotlib on two lines in a row…

%matplotlib
%matplotlib

@josef-pkt You are right, closing the figure would prevent the user from showing the figure in a script. Also one might want to create several figures in a single notebook cell. Semicolons really seem to be the easiest work around.

It would be great if this plotting worked “out of the box” in IPython Notebook without the user having to set anything special (and without having to explicitly capture the return value). Currently the other pandas plotting (which also takes in ax) does not double plot.