%matplotlib notebook magic can plot on previous plot when plotting from pandas

1,171 views
Skip to first unread message

Denis Akhiyarov

unread,
Mar 29, 2016, 3:27:53 PM3/29/16
to Project Jupyter
`%matplotlib notebook` magic can plot on previous plot when plotting from pandas in jupyter notebooks. I'm not sure if this is an issue with pandas, matplotlib or jupyter?

MinRK

unread,
Mar 30, 2016, 8:36:11 PM3/30/16
to jup...@googlegroups.com

I believe this is the intended behavior of the notebook backend, where open figures on the page behave like open figures in windows when using a GUI. If you want a new figure, you can open a new one:

import matplotlib.pyplot as plt
fig = plt.figure()
...

Or you can close the existing figure when you are done with it:

plt.close(plt.gcf()) # or fig if you had a handle on it already

at which point new plot calls will open a new figure.

-Min RK


On Tue, Mar 29, 2016 at 12:27 PM, Denis Akhiyarov <denis.a...@gmail.com> wrote:
`%matplotlib notebook` magic can plot on previous plot when plotting from pandas in jupyter notebooks. I'm not sure if this is an issue with pandas, matplotlib or jupyter?

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/79c85846-cb2e-4dee-a4fb-2f55e4c83a00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Denis Akhiyarov

unread,
Apr 4, 2016, 1:16:26 PM4/4/16
to Project Jupyter
Thank you fro this explanation!

The problem is that figures are separated when plotting pd.DataFrame and figures are added to previous plot when plotting pd.Series.

So adding plt.figure on dataframe.plot() would cause an additional empty figure to appear in current output cell.

Also augmenting previous output cells in the case of series.plot() seems against design of notebook interface. 

This can be quite surprising that your previous plots in output cells have changed, especially if it takes long time to render them.

Thomas Kluyver

unread,
Apr 4, 2016, 1:53:11 PM4/4/16
to Project Jupyter
On 4 April 2016 at 10:16, Denis Akhiyarov <denis.a...@gmail.com> wrote:
The problem is that figures are separated when plotting pd.DataFrame and figures are added to previous plot when plotting pd.Series.

This sounds like something you need to take up with pandas, then. Neither Jupyter nor IPython does anything differently depending on whether you're using a DataFrame or a Series.
Reply all
Reply to author
Forward
0 new messages