You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nbagg: "Close figure" action does not 'close' the figure object #4281
I am not fully sure how the notebook backend is supposed to work (and I also did not found any documentation on it?), but the following did surprise me a bit:
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2*np.pi, 1024)
plt.plot(t, np.sin(t), t, -np.sin(t))
The above creates an interactive figure in the notebook.
But when I close it (the red button with cross) and the figure is displayed in the notebook as a static image, a subsequent plotting call does nothing:
plt.plot(t, np.sin(t), t, np.cos(t))
It is only when I explicitely create a new figure that it is displayed:
plt.figure()
plt.plot(t, np.sin(t), t, np.cos(t))
or if I explicitly close the previous figures with e.g. plt.close('all').
So to me it seems like the plt.plot call is still seeing the original figure as the current figure and so trying to plot it on this original figure, but as this is already displayed as a static image in the previous cell, this does not do anything.
I don't know if this is on purpose, but e.g. with the qt or gtk backend when you close a figure, plt.plot will create a new figure automatically, and not trying to plot on the current figure anymore (as this is closed).
I think this particular case is not included in the UAT notebook.
You have UAT 5 - No show without plt.show in non-interactive mode, but I was working in interactive mode (I used %matplotlib notebook).
You have UAT 8 - Interactive mode, but this only tests that an subsequent line is plotted on the original figure, not that a new plot is generated for that line if the previous figure was closed.
Executing the cell containing only plt.plot(t, np.sin(t), t, np.cos(t)) will create a nice interactive plot but the selection remains in that same cell, unlike inline or Qt4Agg where the selection moves on to the next cell for execution.
Executing the same cell a second time makes the figure disappear and the selection moves to the next cell for execution. Repeated executions will not display anything until after a plt.close() command, as stated above. Each time plt.close() is executed in this condition, a new error appears on the console:
[IPKernelApp] ERROR | No such comm: 3d1517c3278342538a577515ab22e5a1
Have a similar issue - originally posted in ipython, copying essential here. The behaviour on calling close differs depending on whether you put it in the same cell or a different cell, which to me seems weird. If you do:
No image appears (and the layout is also somewhat broken - using Firefox). Calling gcf() in the next cell does also not show any image (unlike with the previous case). Sometimes you get the previously plotted image if you don't reset the backend by calling %matplotlib notebook.
Also, some people have mentioned that using the oo interface is preferred, but if you are using pandas or seaborn for plotting they work in a procedural way and you don't have control over that, so it still needs to work in procedural mode.
I believe that all of the pandas plotting function take ax as a keyword
argument so that is not a problem. I don't know if seaborn does as well,
but if it does not then this should be reported as a bug against their
project.
Also, some people have mentioned that using the oo interface is preferred,
but if you are using pandas or seaborn for plotting they work in a
procedural way and you don't have control over that, so it still needs to
work in procedural mode.
—
Reply to this email directly or view it on GitHub #4281 (comment)
.
Activity
tacaswell commentedon Mar 26, 2015
It should behave like the GUI backends.
It sounds like one of the call backs is not quite right.
attn @pelson
pelson commentedon Mar 26, 2015
Hmmm. I remember our UAT document explicitly covers these kinds of scenarios.
@jorisvandenbossche - can you try out https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/web_backend/nbagg_uat.ipynb and see that it is behaving as you expect?
jorisvandenbossche commentedon Mar 26, 2015
I think this particular case is not included in the UAT notebook.
You have UAT 5 - No show without plt.show in non-interactive mode, but I was working in interactive mode (I used
%matplotlib notebook).You have UAT 8 - Interactive mode, but this only tests that an subsequent line is plotted on the original figure, not that a new plot is generated for that line if the previous figure was closed.
costerwi commentedon Apr 30, 2015
In my experience:
plt.plot(t, np.sin(t), t, np.cos(t))will create a nice interactive plot but the selection remains in that same cell, unlike inline or Qt4Agg where the selection moves on to the next cell for execution.plt.close()command, as stated above. Each timeplt.close()is executed in this condition, a new error appears on the console:[IPKernelApp] ERROR | No such comm: 3d1517c3278342538a577515ab22e5a1
tritemio commentedon May 21, 2015
Is there any workaround for this problem? This is preventing me to use the
notebookbackend in an introductory workshop.tacaswell commentedon May 22, 2015
The workaround is
plt.close('all')mangecoeur commentedon Jun 1, 2015
Have a similar issue - originally posted in ipython, copying essential here. The behaviour on calling
closediffers depending on whether you put it in the same cell or a different cell, which to me seems weird. If you do:-> figure appears
--> new cell
-> figure image appears (non interactive)
However if you group the commands in a single cell:
No image appears (and the layout is also somewhat broken - using Firefox). Calling
gcf()in the next cell does also not show any image (unlike with the previous case). Sometimes you get the previously plotted image if you don't reset the backend by calling%matplotlib notebook.mangecoeur commentedon Jun 2, 2015
Also, some people have mentioned that using the oo interface is preferred, but if you are using pandas or seaborn for plotting they work in a procedural way and you don't have control over that, so it still needs to work in procedural mode.
tacaswell commentedon Jun 2, 2015
I believe that all of the pandas plotting function take
axas a keywordargument so that is not a problem. I don't know if seaborn does as well,
but if it does not then this should be reported as a bug against their
project.
On Tue, Jun 2, 2015 at 6:27 AM mangecoeur notifications@github.com wrote: