ipympl
ipympl copied to clipboard
max open warning
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?
(%matplotlib widget)
(%matplotlib notebook)
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.
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?
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
The reason we have the warning in people were accumulating enough open figures to OOM their python process...
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.