Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/matplotlib/_pylab_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@ def destroy(cls, num):
It is recommended to pass a manager instance, to avoid confusion when
two managers share the same number.
"""
if all(hasattr(num, attr) for attr in ["num", "_cidgcf", "destroy"]):
if all(hasattr(num, attr) for attr in ["num", "destroy"]):
manager = num
if cls.figs.get(manager.num) is manager:
cls.figs.pop(manager.num)
else:
return
else:
try:
manager = cls.figs.pop(num)
except KeyError:
return
manager.canvas.mpl_disconnect(manager._cidgcf)
if hasattr(manager, "_cidgcf"):
manager.canvas.mpl_disconnect(manager._cidgcf)
manager.destroy()
gc.collect(1)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3294,8 +3294,8 @@ def _update_view(self):

def configure_subplots(self, *args):
plt = _safe_pyplot_import()
tool = plt.subplot_tool(self.canvas.figure)
tool.figure.canvas.manager.show()
self.subplot_tool = plt.subplot_tool(self.canvas.figure)
self.subplot_tool.figure.canvas.manager.show()

def save_figure(self, *args):
"""Save the current figure."""
Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ def new_figure_manager_given_figure(num, figure):
if is_interactive():
manager.show()
figure.canvas.draw_idle()
canvas.mpl_connect('close_event', lambda event: Gcf.destroy(manager))

def destroy(event):
canvas.mpl_disconnect(cid)
Gcf.destroy(manager)

cid = canvas.mpl_connect('close_event', destroy)
return manager

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,8 @@ def subplot_tool(targetfig=None):
"""
Launch a subplot tool window for a figure.

A `matplotlib.widgets.SubplotTool` instance is returned.
A `matplotlib.widgets.SubplotTool` instance is returned. You must maintain
a reference to the instance to keep the associated callbacks alive.
"""
if targetfig is None:
targetfig = gcf()
Expand Down