2

I am using a mixture of Pandas and StatsModels to plot a time series decomposition. I followed this answer but when I call plot() it seems to be plotting a duplicate.

My DataFrame looks like

enter image description here

My index looks like

enter image description here

but when I plot the decomposition I get this

enter image description here

Strangely, if I plot only an element of the decomposition, the duplication does not occur

enter image description here

3 Answers 3

9

Assign the result of res.plot() to something, e.g. fig = res.plot(). The result of that method is a matplotlib.figure. The duplicate is from it's _repr_html_, which the notebook renders since it's the last item in the cell. You can try it yourself with

fig, ax = plt.subplots()
ax.plot([1, 2], [1, 2])
fig

The second method returns a matplotlib axes, which doesn't have a _repr_html so you just see that text above the figure.

6

Adding plt.show() line after Solved the issue for me.

0

You can use ";" end of plotting code. res.plot();

2
  • Consider writing this as a comment. Also, generally using semicolons is discourages in python. Commented Oct 6, 2021 at 13:16
  • Thanks, it works. But why a semi-colon can solve the duplication problem?
    – ronzenith
    Commented Dec 10, 2023 at 4:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.