ipympl icon indicating copy to clipboard operation
ipympl copied to clipboard

max open warning

Open MerlinPendragon opened this issue 7 years ago • 5 comments

Hi, I use ipympl in jupyterlab.%matplotlib widget opens a different figure for the same cell after each run. Soon I'll get this max open warning, which is kinda irritating. %matplotlib notebook has no such issue. Is there a way to not open another figure in the same cell?

image (%matplotlib widget)

image (%matplotlib notebook)

MerlinPendragon avatar Aug 09 '18 02:08 MerlinPendragon

I'll bump this as well because this is one of a few irritating behaviors that need to be resolved. The cleanest way I've seen of dealing with this particular issue is something like this:

plt.close('awesome plot 1')
plt.figure('awesome plot 1')

This way it always clears the previous named instance of the plot. The close command also does nothing on a first pass in which the figure is already closed. This also works with integers, though you run the risk of accidentally closing a different figure since matplotlib creates integer numbered figures by default.

The downside is obviously that you have to uniquely name your figures.

flutefreak7 avatar Mar 22 '19 19:03 flutefreak7

plt.close('all') will also close all open figures.

I think the underlying problem here is that with nbagg when the js-widget is removed from the DOM we tear down the figure on the pyplot side and (try) to release all of the references, however with ipympl because the widget may be shown in multiple contexts.

There needs to be some reference counting to tell when there are no visible figures left?

tacaswell avatar Jun 28 '19 14:06 tacaswell

If you know you will have plenty of ram, you can increase the number of figures before there's a warning:

import matplotlib.pyplot as plt
plt.rcParams['figure.max_open_warning'] = 2000 # default is 20

thomasaarholt avatar Jun 28 '19 15:06 thomasaarholt

The reason we have the warning in people were accumulating enough open figures to OOM their python process...

tacaswell avatar Jun 28 '19 16:06 tacaswell

Hi all, just checking if there are any updates on this. I'm a daily user, and I agree with Merlin that it is pretty irritating.

erickson33 avatar Aug 02 '19 18:08 erickson33