Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5f1d55

Browse files
authored
Merge pull request #18214 from meeseeksmachine/auto-backport-of-pr-18184-on-v3.3.x
Backport PR #18184 on branch v3.3.x (Go back to checking figures for their manager in destroy.)
2 parents 9908136 + 0745b37 commit d5f1d55

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/matplotlib/_pylab_helpers.py

Lines 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

Lines 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()

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,13 @@ def check_alt_backend(alt_backend):
146146
@pytest.mark.parametrize("toolbar", ["toolbar2", "toolmanager"])
147147
@pytest.mark.flaky(reruns=3)
148148
def test_interactive_backend(backend, toolbar):
149-
if backend == "macosx" and toolbar == "toolmanager":
150-
pytest.skip("toolmanager is not implemented for macosx.")
149+
if backend == "macosx":
150+
if toolbar == "toolmanager":
151+
pytest.skip("toolmanager is not implemented for macosx.")
152+
if toolbar == "toolbar2" and os.environ.get('TRAVIS'):
153+
# See https://github.com/matplotlib/matplotlib/issues/18213
154+
pytest.skip("toolbar2 for macosx is buggy on Travis.")
155+
151156
proc = subprocess.run(
152157
[sys.executable, "-c", _test_script,
153158
json.dumps({"toolbar": toolbar})],

0 commit comments

Comments
 (0)