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: 4 additions & 3 deletions lib/matplotlib/_pylab_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ def destroy(cls, num):
@classmethod
def destroy_fig(cls, fig):
"""Destroy figure *fig*."""
canvas = getattr(fig, "canvas", None)
manager = getattr(canvas, "manager", None)
cls.destroy(manager)
num = next((manager.num for manager in cls.figs.values()
if manager.canvas.figure == fig), None)
if num is not None:
cls.destroy(num)

@classmethod
def destroy_all(cls):
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def test_get_default_filename(tmpdir):
assert filename == 'image.png'


def test_canvas_change():
fig = plt.figure()
# Replaces fig.canvas
canvas = FigureCanvasBase(fig)
# Should still work.
plt.close(fig)
assert not plt.fignum_exists(fig.number)


@pytest.mark.backend('pdf')
def test_non_gui_warning(monkeypatch):
plt.subplots()
Expand Down
9 changes: 7 additions & 2 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ def check_alt_backend(alt_backend):
@pytest.mark.parametrize("toolbar", ["toolbar2", "toolmanager"])
@pytest.mark.flaky(reruns=3)
def test_interactive_backend(backend, toolbar):
if backend == "macosx" and toolbar == "toolmanager":
pytest.skip("toolmanager is not implemented for macosx.")
if backend == "macosx":
if toolbar == "toolmanager":
pytest.skip("toolmanager is not implemented for macosx.")
if toolbar == "toolbar2" and os.environ.get('TRAVIS'):
# See https://github.com/matplotlib/matplotlib/issues/18213
pytest.skip("toolbar2 for macosx is buggy on Travis.")

proc = subprocess.run(
[sys.executable, "-c", _test_script,
json.dumps({"toolbar": toolbar})],
Expand Down