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

Skip to content

Commit 5426474

Browse files
authored
Merge pull request #18184 from QuLogic/revert-canvas-manager-destroy
Go back to checking figures for their manager in destroy.
2 parents 647a966 + db6fb4d commit 5426474

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

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
@@ -154,8 +154,13 @@ def check_alt_backend(alt_backend):
154154
@pytest.mark.parametrize("toolbar", ["toolbar2", "toolmanager"])
155155
@pytest.mark.flaky(reruns=3)
156156
def test_interactive_backend(backend, toolbar):
157-
if backend == "macosx" and toolbar == "toolmanager":
158-
pytest.skip("toolmanager is not implemented for macosx.")
157+
if backend == "macosx":
158+
if toolbar == "toolmanager":
159+
pytest.skip("toolmanager is not implemented for macosx.")
160+
if toolbar == "toolbar2" and os.environ.get('TRAVIS'):
161+
# See https://github.com/matplotlib/matplotlib/issues/18213
162+
pytest.skip("toolbar2 for macosx is buggy on Travis.")
163+
159164
proc = subprocess.run(
160165
[sys.executable, "-c", _test_script,
161166
json.dumps({"toolbar": toolbar})],

0 commit comments

Comments
 (0)