Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ba9f29

Browse filesBrowse files
committed
Go back to checking figures for their manager in destroy.
This is a partial revert of a small part of matplotlib#13581. Fixes matplotlib#18163.
1 parent 7b56226 commit 2ba9f29
Copy full SHA for 2ba9f29

File tree

Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed

‎lib/matplotlib/_pylab_helpers.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_pylab_helpers.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ def destroy(cls, num):
7171
@classmethod
7272
def destroy_fig(cls, fig):
7373
"""Destroy figure *fig*."""
74-
canvas = getattr(fig, "canvas", None)
75-
manager = getattr(canvas, "manager", None)
76-
cls.destroy(manager)
74+
num = next((manager.num for manager in cls.figs.values()
75+
if manager.canvas.figure == fig), None)
76+
if num is not None:
77+
cls.destroy(num)
7778

7879
@classmethod
7980
def destroy_all(cls):

‎lib/matplotlib/tests/test_backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_bases.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def test_get_default_filename(tmpdir):
6060
assert filename == 'image.png'
6161

6262

63+
def test_canvas_change():
64+
fig = plt.figure()
65+
# Replaces fig.canvas
66+
canvas = FigureCanvasBase(fig)
67+
# Should still work.
68+
plt.close(fig)
69+
assert not plt.fignum_exists(fig.number)
70+
71+
6372
@pytest.mark.backend('pdf')
6473
def test_non_gui_warning(monkeypatch):
6574
plt.subplots()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.