Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old matplotlib ipympl figures not getting released at cell refresh #5373

Closed
jkrumbiegel opened this issue Sep 24, 2018 · 7 comments
Closed
Labels
status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@jkrumbiegel
Copy link

If I create a figure like

fig = plt.figure()

using

%matplotlib notebook

and execute the cell 20 times, I get a warning that twenty figures have been opened. Obviously the old figures hang around in the background, even though there is no reference to them anymore. This can get quite memory demanding if the figures have a lot of content and I iteratively refine them.

I've been using a workaround with

if 'fig' in locals():
    plt.close(fig)
fig = plt.figure()

But this is pretty annoying if there are many cells like that. Is this a matplotlib problem because of their caching in the background or a jupyter lab problem because it doesn't release?

Thanks for any input :)

@jasongrout
Copy link
Contributor

%matplotlib notebook doesn't work in JupyterLab, right? I get Javascript Error: IPython is not defined

@jasongrout
Copy link
Contributor

%matplotlib notebook
from matplotlib import pyplot as plt
fig = plt.figure()

gives an error for me in JupyterLab.

@jasongrout
Copy link
Contributor

(it sounds like the error you are mentioning is a kernel error, which would mean it has nothing to do with JupyterLab and has to do with matplotlib or whoever is providing the rendering backend for matplotlib.)

@jasongrout jasongrout added this to the Reference milestone Sep 24, 2018
@jkrumbiegel
Copy link
Author

Oh I'm sorry, I typed notebook from old muscle memory, I meant
%matplotlib ipympl

@jkrumbiegel
Copy link
Author

And this is the warning

RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam figure.max_open_warning).
max_open_warning, RuntimeWarning)

@jasongrout
Copy link
Contributor

Thanks, that makes more sense. This is a warning from ipympl. The discussion about it is over at matplotlib/ipympl#4. It looks like the discussion there has stalled - perhaps you'd like to start it up again, or at least post your workaround?

@jasongrout
Copy link
Contributor

(Closing here so we can move the discussion over to matplotlib/ipympl#4)

@lock lock bot added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Aug 8, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

No branches or pull requests

2 participants